Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 12:00 13 Nov 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : SPI question

Author Message
Tinine
Guru

Joined: 30/03/2016
Location: United Kingdom
Posts: 1646
Posted: 01:00pm 08 Nov 2019
Copy link to clipboard 
Print this post

Haven't done much with SPI and I RTFM but am still confused:


So this following code works well and MSB comes first. I then sum the bytes to get a 32bit "Count"...


SPI OPEN 10000000, 0, 8 ' speed is 10MHz and the data size is 8 bits

PIN(69) = 0 ' assert the enable line (active low)
junk = SPI(&H60) ' send the command and ignore the return
byte1% = SPI(0) << 24 ' get the first byte from the slave
byte2% = SPI(0) << 16' get the second byte from the slave
byte3% = spi(0) << 8
byte4% = spi(0)
Count% = byte1% + byte2% + byte3% + byte4%
PIN(69) = 1 ' deselect the slave'


Reading about the "Bulk Read", as an option, it suggests loading the bytes into an array...I would still need to build the required 32bit value.

Is it possible to OPEN as 32 bits and simply read directly into a MM integer?:


SPI OPEN 10000000, 0, 32
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10573
Posted: 03:03pm 08 Nov 2019
Copy link to clipboard 
Print this post

Yes and no obviously  

At least on the Armmites you can open for 32-bit and it will read into an integer. However, in your example, this would also send the &H60 as a 32-bit transmission which would almost certainly bugger things up.

The better way of doing it is to use STR2BIN on the input string - check the ArmmiteH7 or MM(+) manual for details - deals with big-endian, little endian and different string sizes
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025