Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 15:23 06 Jul 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 : MCP3302 Interfacing

Author Message
Cremo
Newbie

Joined: 21/07/2015
Location: Italy
Posts: 36
Posted: 08:58am 01 Oct 2016
Copy link to clipboard 
Print this post

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 Kingdom
Posts: 10209
Posted: 09:09am 01 Oct 2016
Copy link to clipboard 
Print this post

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: Italy
Posts: 36
Posted: 09:35am 01 Oct 2016
Copy link to clipboard 
Print this post

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: Australia
Posts: 1114
Posted: 04:41pm 01 Oct 2016
Copy link to clipboard 
Print this post

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: Italy
Posts: 36
Posted: 12:45am 02 Oct 2016
Copy link to clipboard 
Print this post

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: Germany
Posts: 1573
Posted: 01:27am 02 Oct 2016
Copy link to clipboard 
Print this post

  Cremo said  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.

bitreverse

causality ≠ correlation ≠ coincidence
 
Cremo
Newbie

Joined: 21/07/2015
Location: Italy
Posts: 36
Posted: 04:04am 02 Oct 2016
Copy link to clipboard 
Print this post

Hi twofingers, thank you.
Pietro
 
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