Exact match. Not showing close matches.
PICList
Thread
'[PIC]: I2C Master Mode Read'
2005\12\27@111059
by
Roberts II, Charles K.
|
Hello All
I have an AD5321 that is connected to a 16F873A via the MSSP module. I
have the PIC writing data to the D/A. The PIC is in Master Mode. To
start a read of the AD5321 I must send it a byte, b"00011111", then wait
for a acknowledge state from the AD5321 by it pulling down the SCL line.
Then it will send me the MSB of my data and wait on a acknowledge state
from the PIC (Pulling SCL low) then send the LSB and then there should
be no acknowledge from the PIC and a stop condition generated by the
PIC. Here is my code that I have tried to implement it with. This does
not include the MSSP set up code. Comments were removed to save space.
What is wrong with my implementation? Chuck Roberts
DISABLE_IRQ
BANK1
BSF SSPCON2,SEN
BANK0
BTFSS PIR1,SSPIF
GOTO $-1
BCF PIR1,SSPIF
BANK0
MOVLW DA_ADDRESS2
MOVWF SSPBUF
BTFSS PIR1,SSPIF
GOTO $-1
BCF PIR1,SSPIF
BANK1
BSF SSPCON2,PEN
BANK0
BTFSS PIR1,SSPIF
GOTO $-1
BCF PIR1,SSPIF
BANK1
BSF SSPCON2,RCEN
BANK0
BTFSS PIR1,SSPIF
GOTO $-1
BCF PIR1,SSPIF
BANK1
BTFSS SSPSTAT,BF
GOTO $-1
BANK0
MOVF SSPBUF,W
MOVWF DAC_RH
BANK0
BTFSS PIR1,SSPIF
GOTO $-1
BCF PIR1,SSPIF
BANK1
BTFSS SSPSTAT,BF
GOTO $-1
BANK0
MOVF SSPBUF,W
MOVWF DAC_RL
BANK0
ENABLE_IRQ
RETURN
2005\12\27@114829
by
Josh Koffman
On 12/27/05, Roberts II, Charles K. <spam_OUTrobertsckTakeThisOuT
ornl.gov> wrote:
<snip>
> Comments were removed to save space.
> What is wrong with my implementation? Chuck Roberts
I'm sure you'll get other comments like this, but your code is
infinitely harder to read without comments. Heck, unless they have a
familiar coding style, I find other people's code _with_ comments can
get difficult at times. Unless you wrote a book in your comments,
include them. At the very least I've seen numerous times where someone
will say what they want to do in the comments, but there is a typo in
the actual code. With your post, I have no idea what you're expecting
to do with the code.
Just some advice!
Josh
--
A common mistake that people make when trying to design something
completely foolproof is to underestimate the ingenuity of complete
fools.
-Douglas Adams
2005\12\27@125919
by
Roberts II, Charles K.
|
This code is designed to read the status and settings of the AD5321 D/A. And write the two data bytes to DAC_RL,DAC_RH. The macro's and initialization code come from the Tony Kübek full initialization code on the PIC list site. This code is not reading back any values. The read process was described in my first email. What am I doing wrong in the implementation of the read process?
Chuck
READ_DAC_DIRECT
DISABLE_IRQ ;MACRO to disable global interrupt
BANK1 ;MACRO to change bank settings
BSF SSPCON2,SEN ;set start bit
BANK0
BTFSS PIR1,SSPIF ; wait for interrupt flag to be set TEST!!
GOTO $-1
BCF PIR1,SSPIF
BANK0
MOVLW DA_ADDRESS2
MOVWF SSPBUF ;send out the address
; wait for the write to complete before we return
BTFSS PIR1,SSPIF ; wait for interrupt flag to be set
GOTO $-1
BCF PIR1,SSPIF ;clear irq flag
BANK1
BSF SSPCON2,PEN ;set stop bit
BANK0
BTFSS PIR1,SSPIF ; wait for interrupt flag to be set TEST!!
GOTO $-1
BCF PIR1,SSPIF
;*******************************************************************
;This portion of the code will read the data from the DAC
;will write data to DAC_RH and DAC_RL
;
;
BANK1
BSF SSPCON2,RCEN ;enables read
BANK0
; wait for the write to complete before we return
BTFSS PIR1,SSPIF ; wait for interrupt flag to be set
GOTO $-1
BCF PIR1,SSPIF ;clear irq flag
BANK1
BTFSS SSPSTAT,BF ;Checks if read buffer is full
GOTO $-1
BANK0
MOVF SSPBUF,W ;reads contents of buffer
MOVWF DAC_RH ;writes to register to pass out of routine
; wait for the write to complete before we return
BTFSS PIR1,SSPIF ; wait for interrupt flag to be set
GOTO $-1
BCF PIR1,SSPIF ;clear irq flag
BANK1
BTFSS SSPSTAT,BF ;Checks if read buffer is full
GOTO $-1
BANK0
MOVF SSPBUF,W ;reads contents of buffer
MOVWF DAC_RL ;writes to register to pass out of routine
ENABLE_IRQ
RETURN ; and return
2005\12\27@125934
by
olin piclist
Roberts II, Charles K. wrote:
> Comments were removed to save space.
My reply was deleted to save space.
******************************************************************
Embed Inc, Littleton Massachusetts, (978) 742-9014. #1 PIC
consultant in 2004 program year. http://www.embedinc.com/products
2005\12\27@131209
by
olin piclist
Roberts II, Charles K. wrote:
> What am I doing wrong in the implementation of the read process?
I was going to reply in line with your code, but you put tab characters in
the code so it looked like a mess on my screen.
I think your address byte is wrong, but I didn't look at the code closely
because it was too much of a mess.
******************************************************************
Embed Inc, Littleton Massachusetts, (978) 742-9014. #1 PIC
consultant in 2004 program year. http://www.embedinc.com/products
More... (looser matching)
- Last day of these posts
- In 2005
, 2006 only
- Today
- New search...