Picomite issues with MCP3002, dual channel ADC SPI


Author Message
apalert
Newbie

Joined: 06/07/2023
Location: Australia
Posts: 30
Posted: 03:06am 31 Jan 2025      

Have connection but data returned is rubbish. Any tips or clues gladly appreciated.

My code below is modified from Appendix D in Picomite User Manual


OPTION BASE 1                   ' array will start with the index 1
DIM data%(2)                    'array for receiving channel 1 data
dim data2%(2)                   'array for receiving channel 2 data
SETPIN GP8, GP15, GP14, SPI2    ' assign the I/O pins, RX, TX, CLK
PIN(27) = 1 : SETPIN 27, DOUT   'pin 27 ADC chip enable active low
SPI2 OPEN 5000000, 1, 8         ' speed is 5MHz, 8 bits data
PIN(27) = 0                     ' assert the enable line (active low)
SPI2 WRITE 2, 104, 0             ' initialise ADC channel 0
SPI2 READ 2, data%()            ' get two bytes from ADC

SPI2 WRITE 2, 120, 0              ' initialise ADC, channel 1
SPI2 READ 2, data2%()            ' get two bytes from the slave

PIN(27) = 1                      ' deselect the slave
SPI2 CLOSE                       ' and close the channel

'output to console
? bin$(data%(1)), bin$(data%(2)), bin$(data2%(1)), bin$(data2%(2))