I took the data from the bus. I tried to repeat, to send data from the arduino, but the drone does not perceive the answers. The files contain scanned data from the bus when everything is ok fimi and when connecting the arduino test, I understand the arduino does not have time to respond?
AKKUM_1.zip (88,7 КБ)
Have you seen this [SOLVED] SMBus and I²C-Wire-Library ?
Yes.
I couldn't connect to execute this code. error in the library i2cmaster.h
I am creating a slave device, a battery emulator.
My code:
#include <Wire.h>
#define bl03_address 0x0B
int marker = 0;
uint8_t return7[]={0x00, 0x00}; // 0x06
byte i2c_rcv = 0;
//вывод на печать в 16 ричном формате
void hex(byte s){
if (s < 0x10){
Serial.print(0);
Serial.print(s, HEX);
}
else{
Serial.print(s, HEX);
}
}
void setup() {
Serial.begin(250000);
Wire.begin(bl03_address);
Wire.onReceive(dataRcv); // зарегистрируйте обработчик события для полученных данных
Wire.onRequest(dataRqst); //зарегистрируйте обработчик событий для запросов данных
Serial.println("setup");
}
void loop() {}
//чтение запроса от ведущего устройства
void dataRcv(int howMany)
{
Serial.print(howMany);
Serial.print(" - Пришл запрос: ");
while(Wire.available()) { // read all bytes received
i2c_rcv = Wire.read();
hex(i2c_rcv);
}
}
sounds interesting to be used as a dummy battery on old thinkpads. What error do you get?
Now I have achieved that the drone perceives the data, but not everything, writes a battery error when trying to send to the 0xFF command. I highlighted the packets in red in the data upload file from the scanner. These commands are not included in the SMBUS description.
I'm trying to answer like this:
byte FF34A02[]={0x00,0x00}; //0xFF x03 x4A x00 x02
byte FF32402[]={0x00,0x00}; //0xFF x03 x24 x00 x02
byte FF35301[]={0x01}; //0xFF x03 x53 x00 x01
byte FF3C401[]={0x00}; //0xFF x03 xC4 x00 x01
byte FF3C501[]={0x00}; //0xFF x03 xC5 x00 x01
byte FF3C601[]={0x00}; //0xFF x03 xC6 x00 x01
byte FF3CC06[]={0x86, 0xF9, 0x8E, 0x1C, 0xDB, 0x2D}; //0xFF x03 xCC x00 x06 (63878 7310 11739)
byte FF37602 []={0x03, 0xF6}; //0xFF x03 x76 x00 x02
byte FF38202 []={0x03, 0xE9}; //0xFF x03 x82 x00 x02
byte FF6026CA []={}; //0xFF x60 x26 xCA
byte ff61b82f []={0x27,0xC6,0x20}; //0xFF x61 xB8 x2F
byte ff6026ca[] = {}; //0xff 0x60 0x26 0xca
void readFF(){
Serial.print(" Отвечаем на запрос FF: ");
if(i2c_ff == "ff34a02"){
marker = Wire.write(FF34A02, 2);
Serial.print(i2c_ff);
Serial.print(" || ");
Serial.println(marker);
return;
}
else if(i2c_ff == "ff32402"){
Serial.println(i2c_ff);
Wire.write(FF32402, 2);
}
else if(i2c_ff == "ff35301"){Serial.println(i2c_ff);Wire.write(FF35301, 1);}
else if(i2c_ff == "ff3c401"){Serial.println(i2c_ff);Wire.write(FF3C401, 1);}
else if(i2c_ff == "ff3c501"){Serial.println(i2c_ff);Wire.write(FF3C501, 1);}
else if(i2c_ff == "ff3c601"){Serial.println(i2c_ff);Wire.write(FF3C601, 1);}
else if(i2c_ff == "ff3cc06"){Serial.println(i2c_ff);Wire.write(FF3CC06, 6);}
else if(i2c_ff == "ff37602"){Serial.println(i2c_ff);Wire.write(FF37602, 2);}
else if(i2c_ff == "ff38202"){Serial.println(i2c_ff);Wire.write(FF38202, 2);}
else if(i2c_ff == "ff61b82f"){Serial.println(i2c_ff);Wire.write(ff61b82f, 3);}
else if(i2c_ff == "ff60506"){Serial.println(i2c_ff);Wire.write(ff60506, 2);}
else if(i2c_ff == "ff61ec59"){Serial.println(i2c_ff);Wire.write(ff61ec59, 2);}
else if(i2c_ff == "ff60819d"){Serial.println(i2c_ff);Wire.write(ff60819d, 2);}
else if(i2c_ff == "ff612eca"){Serial.println(i2c_ff);Wire.write(ff612eca, 3);}
}
// отправка данных
void dataRqst()
{
Serial.println(" Вызвана функция для ответа ");
switch(i2c_rcv){
case 0x06:
marker = Wire.write(r0x06, sizeof(r0x06));
//Serial.println(marker);
break;
case 0x1B: Wire.write(r0x1B, sizeof(r0x1B)); break;
case 0x1D: Wire.write(r0x1D, sizeof(r0x1D)); break;
case 0xFF:
readFF();
break;
сканер.zip (606,6 КБ)
test1_smbus.ino (6,8 КБ)
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.

