Hola todos.
Tengo un convertidor DC/DC el cual trabaja con el protocolo PMBUS. Un ejemplo de comando es:
Command: READ_VIN
Code: 0x88
Description: Returns the input voltage of the module
Type: Read word
Se que el protocolo de comunicación PMbus es parecido al I2C pero no igual. Para I2C está la librería WIRE. Mi duda es: ¿existe librería exclusiva para PMbus? si la respuesta es no, ¿cómo podría adaptarlo para este ejemplo? de forma que devolviese por el puerto serie de arduino el voltaje de entrada y visualizarlo así en el terminal. Con la poca información que he encontrado se me ocurre algo así, configurando el DC/DC en la dirección: 0x42:
#include <Wire.h>
/* Address */
const byte VCCINT = 0x42;
/* Command */
const byte READ_VIN = 0x88;
/* Register values */
double Vi = 0;
/* Function Prototype */
double ByteRequest(byte DeviceAddr, byte Command, int format); // format : 0 linear11, 1 linear16
double linear11(byte msb, byte lsb);
double linear16(byte msb, byte lsb);
void setup() {
Serial.begin(9600);
Wire.begin();
Wire.setClock(100000L);
}
void loop() {
Serial.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
Vi = ByteRequest(VCCINT, READ_VIN, 0);
Serial.print("Vout = ");
Serial.print(Vi);
Serial.println(" V");
delay(2000);
}
double ByteRequest(byte DeviceAddr, byte Command, int format){
byte ReceiveData = 0x00;
int wen = 0;
byte msb = 0;
byte lsb = 0;
double res = 0;
Wire.beginTransmission(DeviceAddr);
Wire.write(Command);
wen = Wire.endTransmission((uint8_t) false);
if (wen != 0) {
Serial.print("endTransmission error ");
Serial.println(wen);
}
Wire.requestFrom((uint8_t) DeviceAddr, (uint8_t) 2, (uint8_t) true);
if (Wire.available()) {
lsb = Wire.read();
msb = Wire.read();
} else {
Serial.println("No data on bus\r\n");
}
if(format==1)
res = linear16(msb,lsb);
else
res = linear11(msb,lsb);
Wire.beginTransmission(DeviceAddr);
Wire.write(Command);
wen = Wire.endTransmission((uint8_t) true);
return res;
}
Gracias.