Hi,
Has anyone tried interfacing to the MCP3221 ADC via I2C ?
I have the PicKit1 and the MCP3221 Pictail board that puts a direct connection between the RC0, RC1 and SCA SCL. I wanted to test out PicBasic I2C routines linking the 16F630 to the MCP3221.
Problem is that I do not seem to be getting any reading from the ADC. Can anyone suggest where I have gone wrong:
Code:
include "modedefs.bas"
' PIC Defines
' -----------
@ __config _INTRC_OSC_NOCLKOUT & _WDT_ON & _PWRTE_ON & _MCLRE_OFF & _BODEN & _CP_OFF & _CPD_OFF
' PIC16F630
' PIN NAME USE/CONNECTION
' 1 Vdd +5VDC
' 2 RA.5 NC
' 3 RA.4 NC
' 4 RA.3 NC
' 5 RC.5 NC
' 6 RC.4 NC
' 7 RC.3 NC
' 8 RC.2 NC
' 9 RC.1 SCL
' 10 RC.0 SCA
' 11 RA.2 NC
' 12 RA.1 LED1 K, LED2 A
' 13 RA.0 LED1 A, LED2 K
' 14 Vss GND
Define OSCCAL_1K 1 ' Set OSCCAL for 1K
DEFINE OSC 4 ' 4 MHz OSC
CMCON = 7 ' PortA = digital I/O
VRCON = 0 ' Voltage reference disabled
TRISA = %00000000' PortA.0-4 = outputs
TRISC = %00000001' PortC.1-5 = outputs PORTC.0 = input
SDA var PORTC.0
SCL var PORTC.1
B0 var byte
B1 var byte
B2 var byte
cont con %10011011
loop:
I2CREAD SDA,SCL,cont,[B1,B2] 'Read 2 locations in a row
if B1 > 2 then
HIGH PORTA.1
LOW PORTA.2
ELSE
LOW PORTA.1
HIGH PORTA.2
Endif
PAUSE 500
Goto loop ' Go back to loop and blink LED forever
End
'goto loop
Thanks,
Rod
Bookmarks