asp87
Junior Member level 1
- Joined
- Feb 16, 2008
- Messages
- 19
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,281
- Activity points
- 1,427
Hi,
I'm trying to communicate with **broken link removed**(12 bit ADC) through SPI using PIC18f4550.
MCP3201 should start A to D conversion once the chip_select goes low. After 1.5 clocks, it'll finish sampling and send out the digital data MSB first.
My problem:
The code runs till the label "start_conversion" but not after that. I know this from the status of two LEDs, the commands for which are written before and after the start_conversion label. Can you please look into the code and tell where I'm going wrong?
In SPI protocol, when does the PIC start transmitting clock signal? Right after configuring or do we need to do something for it to start transmission? I measured the voltage at PIC RB1 pin (SCLK). It's 0V. Does it mean there is no clock signal?
**broken link removed**
I'm trying to communicate with **broken link removed**(12 bit ADC) through SPI using PIC18f4550.
MCP3201 should start A to D conversion once the chip_select goes low. After 1.5 clocks, it'll finish sampling and send out the digital data MSB first.
My problem:
The code runs till the label "start_conversion" but not after that. I know this from the status of two LEDs, the commands for which are written before and after the start_conversion label. Can you please look into the code and tell where I'm going wrong?
In SPI protocol, when does the PIC start transmitting clock signal? Right after configuring or do we need to do something for it to start transmission? I measured the voltage at PIC RB1 pin (SCLK). It's 0V. Does it mean there is no clock signal?
Code:
LIST P=18F4550 ;directive to define processor
#include <P18F4550.INC> ;processor specific variable definitions
cblock 0x20
d1
d2
d3
RxData
endc
CONFIG FOSC=HS ; HS oscillator, HS used by USB
CONFIG PWRT=ON ; Power on timer
CONFIG BOR=OFF ; Brown out off
CONFIG WDT=OFF ; Watch dog off
CONFIG PBADEN=OFF ; Port B en digital IO
CONFIG LVP=OFF ; Pas de prog single supply
CONFIG ICPRT=OFF ; Port de debug off
CONFIG DEBUG=OFF ; Debug off
org 0x00
goto main
org 0x10
main
bcf INTCON, GIE
movlw b'10000000' ; Fosc/64
movwf SSPSTAT
movlw 0x22 ; 0001 0110
movwf SSPCON1
movlw 0x00
movwf LATB
movwf LATC
movwf LATD
movwf TRISC ; RC7 is SDO
movwf TRISD
movlw b'00000001' ; RB0 is SDI, RB1 is SCLK
movwf TRISB
bsf LATD,2 ; bring chip_select high
call Delay
bcf LATD,2 ; bring chip_select low to start A to D conversion
bsf LATD,0 ; Green LED- This LED lights up
start_conversion
btfss SSPSTAT, 0
bra start_conversion
movf SSPBUF, 0
movwf RxData
bsf LATD,1 ; Red LED - This does not light up
movlw 0x0A
movwf EEADR
movlw RxData
movwf EEDATA
bcf EECON1, EEPGD
bcf EECON1, CFGS
bsf EECON1, WREN
bcf INTCON, GIE
movlw 55h
movwf EECON2
movlw 0AAh
movwf EECON2
bsf EECON1, WR
bcf EECON1, WREN
loop_1
nop
bra loop_1
;---------------------------------------------------------------------
Delay ;0.5 s, 20MHz
movlw 0x01
movwf d1
movlw 0x01
movwf d2
movlw 0x02
movwf d3
Delay_0
decfsz d1, f
bra $+4
decfsz d2, f
bra $+4
decfsz d3, f
bra Delay_0
bra $+2
bra $+2
return
end
**broken link removed**