Re: Problem with I2C
- From: "galapogos" <goister@xxxxxxxxx>
- Date: 6 Dec 2006 02:43:50 -0800
Paul Carpenter wrote:
On 5 Dec, in article
<1165369825.395623.117700@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>
goister@xxxxxxxxx "galapogos" wrote:
Paul Carpenter wrote:
On 4 Dec, in article
<1165304918.361673.137080@xxxxxxxxxxxxxxxxxxxxxxxxxxx>
goister@xxxxxxxxx "galapogos" wrote:
galapogos wrote:
Paul Carpenter wrote:
On 4 Dec, in article
<1165253652.590662.58080@xxxxxxxxxxxxxxxxxxxxxxxxxxx>
goister@xxxxxxxxx "galapogos" wrote:
.....
Cool. I initialized my MCU to a slave receiver and now it acknowledges
the first device address, so there's no resending. I also managed to
get the MCU to interrupt on all subsequent data bytes, but I'm still
not able to send the correct data over. The data is either 0x80 of 0xfd
OK scratch that. The data that is sent is actually always 0x80, and I'm
not sure why that's the case. I'm sending 16 bytes of data over to the
master, and the initial handshaking is all fine until I actually send
data over by writing my data to my serial buffer SBI0DBR, but when I
immediately copy this data over to another junk variable, it reads
0x80, and according to my logic analyzer waveform, it is also 0x80, so
it looks like the MCU is indeed sending whatever is in the buffer, but
the buffer isn't being updated with what I actually want to send...
First *ASSUMPTION* the first data byte of the 16 data bytes to send
should be 0x80 ?
No, it is 0x00 to 0x10 in sequence. 0x80 isn't part of the data array
at all. In fact, I tried sending dummy constants but I always get 0x80
instead.
Are you sending a block of 16 bytes or 16 single byte read equences?
I enter the MCU's ISR after each ACK sent/received. Each time I enter
the ISR I send or receive 1 byte, so I guess I'm sending 16 single byte
sequences?
Check when changing to send first byte you change to transmit and have
set up everything and be sure it is in transmit mode before writing data
to controller.
Actually I'm not even sure if I can even change the transmit direction
on the fly. The control register that the transmit direction is at is
shared with the status register, so within my ISR, I check to see if
it's in transmit mode. If it is, then I'll send data, if not I'll
receive. It's really up to the hardware to tell me if it's in transmit
or receive mode AFAIK.
....
This suggests that you have not coded properly for interupt routines and
all the variables used.
Are the variables used by other functions and interupt routine
defined as volatile?
Variables modified by the ISR are declared volatile. Should those that
are simply read but not written to by the ISR also be declared
volatile?
YES if they are defined elsewhere (e.g. base pointer)
Are you sure that the index(pointer) starts at beginning of buffer?
Yes it is initialized to 0 in the init function
Are you sure that the index/pointer is reset correctly
at end of buffer to beginning of buffer?
What do you mean? The index never goes beyond the end of the buffer
Well anything could be happening.
Are you sure nothing else changes the index/pointer?
Pretty sure but I'll check
Are you sure the data is correct in the table?
Yes most definitely.
Are you sure the index/pointer is incrementing correctly and not
been optimised away. You need a way to get this value every time
used and be sure it is a real value.
You mean optimized by the compiler? How do I prevent this? By declaring
it as volatile?
If the index is incremented once EACH interupt call it is possible the
compiler optimises the increment away, for interupt routines and values
used there and elsewhere I would always make those variables volatile to
be on the safe side as a start point.
I understand. Better be safe than sorry. I've modified all the isr
variable declarations to be volatile, but it didn't change the program
behavior.
.
- Follow-Ups:
- Re: Problem with I2C
- From: Paul Carpenter
- Re: Problem with I2C
- References:
- Problem with I2C
- From: galapogos
- Re: Problem with I2C
- From: Dan Henry
- Re: Problem with I2C
- From: galapogos
- Re: Problem with I2C
- From: Paul Carpenter
- Re: Problem with I2C
- From: galapogos
- Re: Problem with I2C
- From: Paul Carpenter
- Re: Problem with I2C
- From: galapogos
- Re: Problem with I2C
- From: Paul Carpenter
- Re: Problem with I2C
- From: galapogos
- Re: Problem with I2C
- From: Paul Carpenter
- Re: Problem with I2C
- From: galapogos
- Re: Problem with I2C
- From: galapogos
- Re: Problem with I2C
- From: Paul Carpenter
- Re: Problem with I2C
- From: galapogos
- Re: Problem with I2C
- From: Paul Carpenter
- Problem with I2C
- Prev by Date: Re: Problem with I2C
- Next by Date: Re: Problem with I2C
- Previous by thread: Re: Problem with I2C
- Next by thread: Re: Problem with I2C
- Index(es):
Relevant Pages
|