Click the above to check the I2C packet structure. I am not getting any response from the slave. This is my master code.
I am writing to the slave and requesting for every 100 ms, and there is no response form the slave device. help me.
#include <Wire.h>
#include <TimerOne.h> // Header file for TimerOne library
//#ifndef TWI_FREQ
//#define TWI_FREQ 100000L
//#endif
#define LED0 13 // Pin 3
#define TIMER_US 100000 // 100mS set timer duration in microseconds
char send_data[8] = {'F','F','F','F','F','F','F','F'}; //dummy initial values
char receive_data[8] = {'1','1','1','1','1','1','1','1'}; //dummy initial values
int message_flag = 0;
void setup()
{
pinMode(LED0, OUTPUT); // Set the pins as outputs
Timer1.initialize(TIMER_US); // Initialise timer 1
Wire.begin();
Wire.setClock(100000);
Serial.begin(9600);
}
void loop()
{
Timer1.attachInterrupt( timerIsr ); // attach the ISR routine here
if(message_flag == 1)
{
Wire.beginTransmission(0x20); // transmit to device #8
Serial.println("Arduino to HMI");
// for(int i=0; i<8; i++)
// {
// Wire.write(send_data*); // sends five bytes*
// Serial.print(send_data*);
_// }_
_ Wire.write(0x40);_
_ Wire.write(0x00);_
_ Wire.write(0x00);_
_ Wire.write(0x00);_
_ Wire.write(0x41);*_
* Serial.println(" ");*
* Wire.endTransmission(); // stop transmitting*
* Wire.requestFrom(0x20, 8);*
* while(Wire.available() > 1)*
* {*
* Serial.println("HMI to Arduino");*
* for(int j =0; j<8; j++)*
* {*
* receive_data[j] = Wire.read();
Serial.print(receive_data[j]);
_ }_
_ Serial.println("");_
_ }_
message_flag = 0;
_ }_
_}_
void timerIsr()
_{_
_ digitalWrite( LED0, digitalRead( LED0 ) ^ 1 ); // Toggle LED 0*_
* message_flag = 1;
_}*_