Hello All
I am trying to build a prototype to read 16bit data from an external ADC (AD977) via the 18F2553's SPI pins and using the SPI legacy component. I have been able to write a FCF to collect 1.5 bytes of data from the PIC's internal 12bit ADC by using the component macro's "readasint" option, convert this to a string as shown in MM's ADC to USB example, and then send it successfully to the internal USB module for onward transmission.
The problem is that the SPI in Flowcode5 for PIC doesn't have the "readasint" or other binary convertor options but only has "SPI_Get_Char" and "SPI_Get_String" options that are not useful in a digital world. I have checked my Flowcode5 for dsPIC and that too has no facility for collecting digital data from an external ADC but only strings and characters. Can anyone advise me if there is a way round this brick wall.
Thanks
Richard Clarke
External ADC to 18F2553 via SPI
Moderator: Benj
-
randomrichard
- Posts: 41
- Joined: Thu Oct 16, 2008 11:01 am
- Has thanked: 21 times
- Been thanked: 7 times
-
kersing
- Valued Contributor

- Posts: 2045
- Joined: Wed Aug 27, 2008 10:31 pm
- Location: Netherlands
- Has thanked: 553 times
- Been thanked: 1081 times
Re: External ADC to 18F2553 via SPI
The SPI component macro's SPI_Get_Char reads one 8 bit byte. SPI_Get_String reads the specified number of bytes and stores them in a String. The names of the macros can be confusing as they could be interpreted to return ASCII characters/strings but they do return byte(s).
To read an integer value (where the most significant bit is transmitted first) there are two options:
- two calls to SPI_Get_Char, store the result of the first call in (byte) b1 and of the second call in (byte) b2, calculation: i = ( b1 << 8 ) + b2
- one call to SPI_Get_String with length 2, store result in String s (length at least 2), calculation: i = ( s[0] << 8 ) + s[1]
In both cases i should be (unsigned) integer.
To read an integer value (where the most significant bit is transmitted first) there are two options:
- two calls to SPI_Get_Char, store the result of the first call in (byte) b1 and of the second call in (byte) b2, calculation: i = ( b1 << 8 ) + b2
- one call to SPI_Get_String with length 2, store result in String s (length at least 2), calculation: i = ( s[0] << 8 ) + s[1]
In both cases i should be (unsigned) integer.
“Integrity is doing the right thing, even when no one is watching.”
― C.S. Lewis
― C.S. Lewis
-
randomrichard
- Posts: 41
- Joined: Thu Oct 16, 2008 11:01 am
- Has thanked: 21 times
- Been thanked: 7 times
Re: External ADC to 18F2553 via SPI
Kersing
Thank you very much for taking the time to give me the answer, and for the suggested manipulation of the received data.
Richard
Thank you very much for taking the time to give me the answer, and for the suggested manipulation of the received data.
Richard