![]() |
Forum Index : Microcontroller and PC projects : MCP3302 Interfacing
Author | Message | ||||
Cremo Newbie ![]() Joined: 21/07/2015 Location: ItalyPosts: 36 |
Hello, I have problems interfacing the MCP3302 A-D converter using SPI port. My test program is the following: _____________________________________________________ option explicit 'Chip Select A-D const CS_MCP3302 =14 dim integer dati(3) 'to receive 3 bytes 'configure pin as Chip Select of MCP3302A setpin CS_MCP3302,dout 'pin as digital out pin(CS_MCP3302)=1 settick 500, Read_A_D 'periodical reading do ''' loop sub Read_A_D ' ADC reading SPI open 1000000,0,8 pin(CS_MCP3302)=0 'chip select spi write 3,&B00001100,&B00000000,&B00000000 'to configure chip and convert spi read 3,dati() pin(CS_MCP3302)=1 'chip unselect spi close print "data0=",hex$(dati(0)) print "data1=",hex$(dati(1)) print "data2=",hex$(dati(2)) end sub ______________________________________________________- I see meaningless values printed. If I connect a scope with SPI decoding I see correct values on it. Maybe some problem in spi read from Micromite Basic ? The version I us is the 5.2 Plus version. Thank you. Pietro |
||||
matherp Guru ![]() Joined: 11/12/2012 Location: United KingdomPosts: 10209 |
Looking briefly at the datasheet I would say you need Mode 3 rather than 0. There is definitely no problem with SPI in 5.2 |
||||
Cremo Newbie ![]() Joined: 21/07/2015 Location: ItalyPosts: 36 |
Hi Matherp, thank you for your fast reply. Changing the mode does not help. For example if I input to the A-D a voltage to obtain a 1023 value (HEX 3FF), I see the following values: data0= HEX FF, data1 = HEX E0, data2 = HEX 00. Best regards. Pietro |
||||
panky![]() Guru ![]() Joined: 02/10/2012 Location: AustraliaPosts: 1114 |
Pietro, Maybe a bit order problem? If you are receiving lsb first then ff e0 00 becomes 00 03 ff? Just a thought. Doug. ... almost all of the Maximites, the MicromMites, the MM Extremes, the ArmMites, the PicoMite and loving it! |
||||
Cremo Newbie ![]() Joined: 21/07/2015 Location: ItalyPosts: 36 |
Dough, shame on me ! You are right, if I read the bits backward the values are correct. It is only necessary to write a boring function to use the bit sequence in the correct order. Thank you a lot. Pietro |
||||
twofingers![]() Guru ![]() Joined: 02/06/2014 Location: GermanyPosts: 1573 |
bitreverse causality ≠ correlation ≠ coincidence |
||||
Cremo Newbie ![]() Joined: 21/07/2015 Location: ItalyPosts: 36 |
Hi twofingers, thank you. Pietro |
||||
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |