SPI help needed


Author Message
lew247

Guru

Joined: 23/12/2015
Location: United Kingdom
Posts: 1709
Posted: 09:32am 21 Jan 2022      

I'm trying to get my head around SPI communication
I need to send and recieve STRING$ via SPI and I can't understand exactly how to do it
Specifically Im using a Picomite but the same should apply to others so hopefully someone can help

I have searched the forum and read the manual
In the manual it says SPI WRITE nbr, string$

Can anyone explain in simple terms an idiot like me can understand what nbr means exactly please?

I want to send "AT+GMR"  and print out the reply

OPTION BASE 1 ' our array will start with the index 1
DIM a$ ' define the array for receiving the data
SETPIN GP11, GP8, GP10, SPI2 ' assign the I/O pins
SPI2 OPEN 5000000, 11, 8 ' speed is 5MHz, 8 bits data
SPI2 WRITE 0, string$, "AT+GMR" ' send the command
SPI2 READ 20, a$ ' get twenty bytes from the slave
SPI2 CLOSE ' and close the channel
PRINT a$


I did try SPI2 WRITE 1, string$, "AT+GMR", SPI2 WRITE 6, string$, "AT+GMR" and SPI2 WRITE 8, string$, "AT+GMR"
but I get "INCORRECT ARGUMENT COUNT"

I also tried read with many different numbers but I've no idea how many characters the returned string will be



HOW exactly do I read a string that is returned when I actually manage to send the command properly?

In the example in the manual it also has these two lines
If there is no slave SPI device attacted I hope Im right in assume they are not needed?


PIN(10) = 1 : SETPIN 10, DOUT ' pin 10 will be used as the enable signal
PIN(10) = 0 ' assert the enable line (active low)

Can anyone give me an example of code to send the string "AT+GMR" via SPI and read the reply