You need to log in to create posts and topics.
atmega328 i2c slave
bjacquot@bjacquot
5 Posts
#1 · March 13, 2024, 2:59 pm
Quote from bjacquot on March 13, 2024, 2:59 pmHi,i try to use i2c slave mode using arduino lib Wire.h, but that don't work as expected.Very simple programm :#include <Wire.h> const int8_t i2cAddress = 8; void receiveEvent(int nbBytes) { PORTD=Wire.read(); } int main() { DDRD=0xFF; Wire.begin(i2cAddress); Wire.onReceive(receiveEvent); sei(); while(1) { _delay_us(100); //PORTD=TWDR; } }
TWDR register contains right datas but callback function is not executed.it seams TWSR register does not worked as expected. Il should take TW_SR_STOP 0xA0 value but only got TW_SR_DATA_ACK 0x80 and TW_SR_SLA_ACK 0x60
Hi,
i try to use i2c slave mode using arduino lib Wire.h, but that don't work as expected.
Very simple programm :
#include <Wire.h>
const int8_t i2cAddress = 8;
void receiveEvent(int nbBytes)
{
PORTD=Wire.read();
}
int main()
{
DDRD=0xFF;
Wire.begin(i2cAddress);
Wire.onReceive(receiveEvent);
sei();
while(1)
{
_delay_us(100);
//PORTD=TWDR;
}
}
TWDR register contains right datas but callback function is not executed.
it seams TWSR register does not worked as expected. Il should take TW_SR_STOP 0xA0 value but only got TW_SR_DATA_ACK 0x80 and TW_SR_SLA_ACK 0x60
Click for thumbs down.0Click for thumbs up.0
arcachofo@arcachofo
574 Posts
#2 · March 13, 2024, 4:00 pm
Quote from arcachofo on March 13, 2024, 4:00 pmHi.
Thanks for reporting and for the solution.Indeed a Stop condition does not set the correct status value.
Solved at Rev 2255.
Hi.
Thanks for reporting and for the solution.
Indeed a Stop condition does not set the correct status value.
Solved at Rev 2255.
Click for thumbs down.0Click for thumbs up.1
bjacquot has reacted to this post.
bjacquot
#4 · March 21, 2024, 12:36 pm
Quote from bjacquot on March 21, 2024, 12:36 pmit don't work as expected.
You should send TWI_SRX_STOP_RESTART only when the i2c message is for you :if (m_addrMatch) setTwiState( TWI_SRX_STOP_RESTART );
it don't work as expected.
You should send TWI_SRX_STOP_RESTART only when the i2c message is for you :
if (m_addrMatch) setTwiState( TWI_SRX_STOP_RESTART );
Click for thumbs down.0Click for thumbs up.0
arcachofo@arcachofo
574 Posts