X4 Problems reading raw data when using two radar sensors

Discussion in 'X2 & X4 SoC' started by jaeyong, May 20, 2019.

  1. jaeyong

    jaeyong New Member

    I try to get raw data by connecting two X4M07 radar sensors and one raspberrypi
    by referring to the example at https://github.com/xethru/X4Driver_RaspberryPi_Example.
    Reading raw data using one sensor was very successful.
    However, in the process of receiving raw data using two sensors,
    it was not possible to read data from the first initialized radar, and the second radar could read the raw data.
    During the initialization of the second radar in the taskRadar function in taskRadar.cpp,
    I found that the first radar between the task_radar_init () and x4driver_init () functions resulted in an error.
    I have confirmed that the error code is 4 and X4DRIVER_PIF_TIMEOUT.
    If you know why I get this error, let me know and let me know how to fix it.
    (Each radar is configured to use a different SPI channel: radar0 -> 24Pin, radar1 -> 26Pin)

    Attached Files:

  2. Charlie Shao

    Charlie Shao Moderator Staff Member

    Hi Jaeyong,

    This sounds wired but I believe this problem can be solved once you show the initialization part code with us (support@xethru.com). I am also curious about how you are going to use two X4M07 sensors in one setup. If you are able to share more information about your project, we can help you to verify the feasibility of your application.
  3. jaeyong

    jaeyong New Member

    Hi Charlie,

    This is my taskRadar.cpp
    I'd like you to judge whether it's the right way to drive two radar sensors.
    I marked the code I added or edited in red.


    void x4driver_data_ready(int num )

    //Determine which radar to read with the num parameter

    if(num == 0){
    now = x4driver;
    now = x4driver1;

    uint32_t status = XEP_ERROR_X4DRIVER_OK;
    uint32_t bin_count = 0;
    x4driver_get_frame_bin_count(now, &bin_count);
    uint8_t down_conversion_enabled = 0;
    x4driver_get_downconversion(now, &down_conversion_enabled);

    int taskRadar(void)

    printf("task_radar start!\n");

    int fps_set = 1;
    int delay = 1/fps_set*500000;

    uint32_t status = 0;

    // Initializing Radar 0

    status = task_radar_init(&x4driver,0);

    xtx4driver_errors_t tmp_status = (xtx4driver_errors_t)x4driver_init(x4driver);

    status = x4driver_set_sweep_trigger_control(x4driver, SWEEP_TRIGGER_X4);

    status = x4driver_set_dac_min(x4driver, 949);

    status = x4driver_set_dac_max(x4driver, 1100);

    status = x4driver_set_iterations(x4driver, 32);

    status = x4driver_set_pulses_per_step(x4driver, 140);

    status = x4driver_set_downconversion(x4driver, 1);

    status = x4driver_set_frame_area_offset(x4driver, 0);

    status = x4driver_set_frame_area(x4driver, 0.4, 1);

    status = x4driver_check_configuration(x4driver);

    status = x4driver_set_fps(x4driver, fps_set);

    // Initializing Radar 1

    status = task_radar_init(&x4driver1,1);

    tmp_status = (xtx4driver_errors_t)x4driver_init(x4driver1);

    status = x4driver_set_sweep_trigger_control(x4driver1, SWEEP_TRIGGER_X4);

    status = x4driver_set_dac_min(x4driver1, 949);

    status = x4driver_set_dac_max(x4driver1, 1100);

    status = x4driver_set_iterations(x4driver1, 32);

    status = x4driver_set_pulses_per_step(x4driver1, 140);

    status = x4driver_set_downconversion(x4driver1, 1);

    status = x4driver_set_frame_area_offset(x4driver1, 0);

    status = x4driver_set_frame_area(x4driver1, 0.4, 1);

    status = x4driver_check_configuration(x4driver1);

    status = x4driver_set_fps(x4driver1, fps_set); // Generate 5 frames per second

    pinMode(X4_GPIO_INT, INPUT);
    pullUpDnControl(X4_GPIO_INT, PUD_DOWN);


    x4driver_data_ready(0); // << impossible to read data from radar0
    x4driver_data_ready(1); // << possible to read data from radar1


    Reading radar data is read via x4driver_data_ready ()
    in the while statement of the taskRadar function, not by the interrupt service routine. ( disable the ISR )
    I added the channel parameter in task_radar_init and also radar_hal_init in radar_hal.c
    and in radar_handle_t I added SPI_CHANNEL member variable.

    uint32_t task_radar_init(X4Driver_t **x4driver, int channel);


    int radar_hal_init(radar_handle_t ** radar_handle, void* instance_memory, int channel)
    int status = XT_SUCCESS;
    radar_handle_t * radar_handle_local = (radar_handle_t *)instance_memory;
    memset(radar_handle_local, 0, sizeof(radar_handle_t));
    radar_handle_local->radar_id = 0;
    radar_handle_local->SPI_CHANNEL = channel;

    *radar_handle = radar_handle_local;

    pinMode(X4_ENABLE_PIN, OUTPUT);
    pinMode(X4_GPIO_INT, INPUT);
    pullUpDnControl (X4_GPIO_INT, PUD_DOWN);

    wiringPiSPISetup(channel, 500000);

    return status;

    uint32_t radar_hal_spi_write_read(radar_handle_t * radar_handle, uint8_t* wdata, uint32_t wlength, uint8_t* rdata, uint32_t rlength)
    if ((0 == wlength) && (0 == rlength))
    return XT_SUCCESS;
    if ((NULL == wdata) || (NULL == rdata))
    return XT_ERROR;
    return XT_SUCCESS;
  4. Charlie Shao

    Charlie Shao Moderator Staff Member

    Hi Jaeyong,
    I see two issues with your code:
    1. You should use GPIO interrupt to trigger x4driver_data_ready function, this will make sure you can read data with expected FPS. Reading in the loop is not one efficient way.
    2. From the code I found you use one shared X4_GPIO_INT, I suggest you use different GPIO pins on RPI to catch data ready info send by X4_GPIO1 from different sensor modules.
  5. jaeyong

    jaeyong New Member

    Thanks Charlie,

    To summarize your words, when a new radar is added, I need to connect another X4_GPIO1 pin and an SPI_CHANNEL pin? And is it necessary to read the data from each radar with the ISR of the corresponding X4_GPIO1 pin?
  6. Charlie Shao

    Charlie Shao Moderator Staff Member

    Yes, your understanding is correct.
  7. jaeyong

    jaeyong New Member

    Thanks Charlie,
    I am so grateful for your reply.

    I connected two radars using two X4_GPIO1 pins and two SPI_nss pins as you said.
    After that I tried to read the raw data from the ISR of each radar.
    However, when the second x4driver_init () was executed, the data could not be read from the first radar.
    I want you to let me know if there are any anticipated problems.