View previous topic :: View next topic |
Author |
Message |
kongfu1
Joined: 26 Apr 2010 Posts: 56
|
I2C slave is not working with 16f1938 |
Posted: Tue Nov 22, 2011 12:45 am |
|
|
I2C slave is working when master requests one byte to read only. Every time when I2C master reads more than one byte, 16F1938 will hold clock line to be low until reset the chip.
Please help.
Howard
Here is slave interrupt:
Code: |
#INT_SSP
void ssp_interupt ()
{
BYTE incoming, state;
state = i2c_isr_state();
if(state <= 0x80) //Master is sending data
{
incoming = i2c_read();
if(state == 1) //First received byte is address
address = incoming;
if(state == 2) //Second received byte is data
buffer[address] = incoming;
}
if(state == 0x80) //Master is requesting data
i2c_write(buffer[address]);
}
|
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19477
|
|
Posted: Tue Nov 22, 2011 9:48 am |
|
|
Of course it will......
You are not loading any data for the master to read, if it asks for more than one byte. I2C_ISR_STATE, will return 0x81, then 0x82 etc.. For these values the code does nothing, so the clock will be held low, waiting for the buffer to be loaded....
Best Wishes |
|
|
kongfu1
Joined: 26 Apr 2010 Posts: 56
|
|
Posted: Tue Nov 22, 2011 12:26 pm |
|
|
Ttelmah wrote: | Of course it will......
You are not loading any data for the master to read, if it asks for more than one byte. I2C_ISR_STATE, will return 0x81, then 0x82 etc.. For these values the code does nothing, so the clock will be held low, waiting for the buffer to be loaded....
Best Wishes |
Thanks for your quick reply. That was my mistake.
Another word is that, is there any hw timeout of PIC to release I2C clock line if the buffer was never loaded? In my case, reset PIC is only way to release I2C clock line.
Thanks,
Howard |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
|