Hi everyone,
I have an issue with SSI communication, and I need guidance to understand better or to handle the exception which is generated by the code.
- I have a custom board with the tm4c1294ncpdt Tiva C processor
- I have 4x digital sensors ( icm20602 ) which I read from and are connected to the custom board via USB-c
- These sensors can be removed while in operation, and when the sensor is removed the data gathering is stopped and a software reset is triggered on the tiva, to start from the beginning.
Sometimes this sequence does not happen and it goes into a loop then after 10s it performs the reset and everything is fine
I suspect that when I remove the sensor at the exact time when I reed the data from it, it enters into the delay loop
code which is used to red the sensor data into a buffer and then swapping the bytes of the acc and gyro
uint8_t read_icm20602_sensor(uint8_t sensor_id, uint8_t timeout, uint8_t *buffer) { uint8_t drdy_data; uint8_t whoamy_data; uint8_t icm_buff[14]; select_digi_sensor(sensor_id); // SSI1_device_read(WHO_AM_I, 1, &whoamy_data); // if(whoamy_data != WHO_AM_I_DATA_OK) return 0; uint16_t buffer_index = ICM20602_DATA_SIZE * (sensor_id -1); while(timeout--){ SSI1_device_read(INT_STATUS, 1, &drdy_data); if ((drdy_data & 0x01) == 0x01){ SSI1_device_read(ACCEL_XOUT_H, 14, icm_buff); icm20602_buffer_byte_swap(&buffer[buffer_index], icm_buff); return 1; } } return 0; }
function where the SSI read and transmit is implemented
unsigned char SSI1_transmit_data(unsigned char data) { uint32_t rx_buffer; while(SSIDataGetNonBlocking(SSI1_BASE, &rx_buffer)); SSIDataPut(SSI1_BASE, data); while(SSIBusy(SSI1_BASE)); SSIDataGet(SSI1_BASE, &rx_buffer); // while(SSIBusy(SSI1_BASE));// added for testing purpose, this waits till the buffer is full. return rx_buffer & 0x00FF; } void SSI1_device_read(uint8_t address, uint8_t size, uint8_t *buffer) { uint32_t i = 0; SSI1_cs_on(); address |= 0x80; SSI1_transmit_data(address); for(i = 0; i < size; i++){ buffer[i] = SSI1_transmit_data(0xFF); } SSI1_cs_off(); }
Do I oversee something on in the code or the handling of these kind of functionality