![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
Fabri
Joined: 22 Aug 2005 Posts: 275
|
i2c bus comunication |
Posted: Thu Feb 01, 2007 3:57 am |
|
|
Hi,
I use I2C bus for read and write command to slave controll pannel lcd.
I started with example of CCS ex_slave.c. I send address, as command code and then 16 bit data with function write_ext_eeprom();
I use the follow routine to receve address and data:
Quote: |
#INT_SSP
void ssp_interupt (){
BYTE incoming, state;
state = i2c_isr_state();
incoming = i2c_read();
if(state < 0x80) //Master is sending data
{
if(state == 1) //First received byte is address
address = incoming;
if(state == 2){ //Second received byte is data
dato = make16(incoming,0);
}
if(state == 3){ //Second received byte is data
dato += incoming;
// Decode address
switch(address){
case 0x31:
break;
case 0x32:
break;
case 0x33:
break;
case 0x34:
break;
case 0x35:
break;
case 0x36:
break;
}
}
}
if(state == 0x80) //Master is requesting data
{
i2c_write(0x10);
}
}
|
The system receve address and data without problem but when I'll try to decode address, under interrupt service routine, the system don't receve anything else till hardware reset of slave.
Another question is busy situation of slave. Master send 16 char to slave LCD. I send one char each trasmission, and master have to know when the slave are ready to receve next char.
How slave can send busy situation on I2c Bus and let master wait ?
Thanks for help |
|
![](templates/subSilver/images/spacer.gif) |
jds-pic
Joined: 17 Sep 2003 Posts: 205
|
Re: i2c bus comunication |
Posted: Sun Feb 04, 2007 9:04 am |
|
|
Fabri wrote: | Another question is busy situation of slave. Master send 16 char to slave LCD. I send one char each trasmission, and master have to know when the slave are ready to receve next char.
How slave can send busy situation on I2c Bus and let master wait |
you have two options:
1) find out from the LCD datasheet what the minimum wait time is between sending characters. you need to delay_ms() this time between chars.
2) find out from the LCD datasheet if it supports "i2c clock stretching". search here and also google this term to learn more about what this is and what it can do for you in this application.
jds-pic |
|
![](templates/subSilver/images/spacer.gif) |
Fabri
Joined: 22 Aug 2005 Posts: 275
|
|
Posted: Mon Feb 05, 2007 1:34 am |
|
|
Hi,
At the moment, when slave receve last byte of comunication, put in low state SCL line just a time to execute command. Master station, before send new byte, wait I2C bus free state.
I use PIC16F690 and I don't understand why, enabled timer 0 interrupt, the I2C comunication of slave stop to work. I receve the first byte, no more.
I need timer 0 interrupt just to count time and delay without any function in it. Timer 0 interrupt occure every 1 ms and take 4,5 us.
Regards,
Fabri |
|
![](templates/subSilver/images/spacer.gif) |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|