(Jan-17-2022, 03:44 AM)bowlofred Wrote: Can you show the code on the sending and receiving side that transfers the data?
This is on slave side (just adding snippet related to SPI, because its a very long code):
//data transfer variables uint32_t data_adc; uint8_t b1,b2,b3,b4; // Configure MOSI pin as an input GPIO_PinModeSet(US0MOSI_PORT, US0MOSI_PIN, gpioModeInput, 0); // Configure MISO pin as an output GPIO_PinModeSet(US0MISO_PORT, US0MISO_PIN, gpioModePushPull, 0); // Configure CLK pin as an input GPIO_PinModeSet(US0CLK_PORT, US0CLK_PIN, gpioModeInput, 0); // Configure CS pin as an input pulled high GPIO_PinModeSet(US0CS_PORT, US0CS_PIN, gpioModeInput, 1); void initUSART0(void){ //not adding code snippet but these are the setting: 1. set as slave 2. speed: 4000000 3. MSB transferred first 4. 8 data bits 5. clock mode 0 } while(1){ . . USART_SpiTransfer(USART0, 'S'); /* this function performs one 8-bit frame SPI transfer. This function will stall if the transmit buffer is full. When a transmit buffer becomes available, data is written and the function will wait until data is fully transmitted. The SPI return value is then read out and returned. */ for(uint32_t i = 0; i < 98; i++){ data_adc = *((uint32_t *)StartPage+i); //data read from flash memory b1 = (unsigned int)(data_adc & 0xff); b2 = (unsigned int)(data_adc >> 8) & 0xff; b3 = (unsigned int)(data_adc >> 16) & 0xff; b4 = (unsigned int)(data_adc >> 24); int testarray[4]={b4,b3,b2,b1}; for (int i = 0; i < 4; i++){ USART_SpiTransfer(USART0, testarray[i]); //no new line character?? } } USART_SpiTransfer(USART0, 'D'); //'D' will be sent as an integer!! To tell RP, all data has been transferred. . . }Below is code on master side (Raspberry Pi):
# spi.py import time import spidev import array as arr import struct # We only have SPI bus 0 available to us on the Pi bus = 0 #Device is the chip select pin. Set to 0 or 1, depending on the connections device = 0 # Enable SPI spi = spidev.SpiDev() # Open a connection to a specific bus and device (chip select pin) spi.open(bus, device) # Set SPI speed and mode spi.max_speed_hz = 4000000 spi.mode = 0 print("Enter '1' to start the process") a=input() if a: print("SM1 Process started...") spi.xfer2([0x01]) while True: #spi.xfer2([0,0,0,0]) b=spi.readbytes(4) value=struct.unpack("<I", bytearray(b))[0] print (value) else: print("Wrong input.")One thing, I didn't add in the slave code is that: when the slave is powered on, master sends a command, '1' to slave and slave checks if it receives '1'. If it receives '1' then this whole above process is started. So that much communication is happening correctly.