Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

SPI communication with MCP3008

 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-8051
View previous topic :: View next topic  
Author Message
muc82

Bascom Member



Joined: 12 May 2014
Posts: 1

PostPosted: Mon May 12, 2014 6:56 pm    Post subject: SPI communication with MCP3008 Reply with quote

Hi,

I have an problem with communication over SPI. I would like to read an channel from MCP3008 10-bit AD converter. I always get maximum value readout in the controller, also if the MCP is not connected. Has someone experience with communicating over the SPI? Please for help.
My program bellow:

Code:
Dim A1 As Byte , C(2) As Byte
Dim B2 As Word , B3 As Word , B4 As Word , B44 As Word
Dim Cs As Bit

Config Lcdpin = Pin , Db4 = P1.0 , Db5 = P1.1 , Db6 = P1.2 , Db7 = P1.3 , E = P1.4 , Rs = P1.5
Config Spi = Soft , Din = P3.2 , Dout = P3.3 , Cs = P3.4 , Clk = P3.5 , Data Order = Msb , Nocs =

Spiinit

Config Lcd = 20 * 4
Cursor Off Noblink
Cls

A1 = &B00011000
Set Cs

Do

Reset Cs

Spiout A1 , 1
Spiin C(1) , 2
Set Cs
Waitms 50
B2 = C(1)
Shift B2 , Left , 2
Shift C(2) , Right , 6
B3 = C(2)
B4 = B2 + B3

If B4 <> B44 Then
  Cls
  Locate 1 , 1 : Lcd ; "B4  " ; B4

   B4 = B44

   End If

Loop

Return


Any suggestions what is wrong in the program to get readout from the MCP?

Thank you.
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-8051 All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum