cancel
Showing results for 
Search instead for 
Did you mean: 

what is the best protocol to send arrays I2C, SPI ?

MNapi
Senior II

I have array[2000];

I am trying to send from nucleo to arduino, it seems if I send bigger than 8 elements it freezes or does nothing. So I have no problem to send array of 8 elements.

I know that I could do it piece by piece in a for loop, I would have each time to acknowledge and send request for next piece.

I mean some simple protocol, code to get the whole array in one piece.

I am using cube mx and keil

4 REPLIES 4
S.Ma
Principal

SPI with DMA on STM32 as slave mode. Program the DMA to be in circular mode over the buffer and set the DMA when NSS level change (EXTI). There won't be any speed or latency issues besides EXTI ISR duration. If you are limited to 8 bytes, then you would also need to emulate an SPI EEPROM memory as baseline, adding the subadress in the transaction.

SPI is the CMOS serial interface with highest bitrate.

Should probably figure out why 8 bytes/elements fail.

I2C should be providing acknowledgement as part of the protocol. For EEPROM or FLASH the transfer/page length is often 256 bytes, with each page sent with a start address. This can be streamable.

S​PI has a more open form, but one can always send ack or nack data in the return channel.

UART can also be quite effective, you can packetize or synchronize using SLIP, or use XYZ-MODEM​

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..

I am using very simple code, it cannot be simpler

while (1)

 {

       HAL_I2C_Master_Transmit(&hi2c1, 50, i2cValue, 8, 10);

     }

it only works if I made

uint8_t i2cValue[8];

and it keeps transmitting to arduino due, sending data from ADC pin

arduino due has enough ram and flash to handle big array.

but as soon as I do i2cValue[9]; or bigger nothing happens

Does it return an error? Shouldn't be an inherent limit of 8 bytes here. Watch that the timeout expands with the data size to accommodate the transfer time and the margin to flag a true failure. ​

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..