I want to simulate a Smart Battery BMS Slave with SMbus communication.
I found these two topics in this forum that are quite similar, but they seem not to be solved...
http://forum.arduino.cc/index.php?topic=329264.0
http://forum.arduino.cc/index.php?topic=200951.0
I have an Arduino Zero Pro board. The code I am trying is very simple; the master (the PC) sends a command to the arduino by SMBus communication and this board has to send the same command to the master. But this simple code is not working...
#include <Wire.h>
#define SLAVE_ADDRESS 0x0B
int command=0;
void setup() {
Serial.begin(9600);
Wire.begin(SLAVE_ADDRESS);
Wire.onReceive(receiveData);
Wire.onRequest(sendData);}
void loop() {
delay(100);}
void receiveData(int byteCount){
command=Wire.read();
while (Wire.available()){
Wire.read();}
}
void sendData(){
Wire.write(command);
}
if the master sends command "a" to arduino (slave), "0" is sent back to master.
if later, master sends command "d", "140a" is sent to master.
if later, master sends command "e", "1a0d" is sent to master...
Has anyone know where could the error be??