Hello, I'm trying to comunicate my arduino Uno with power inverter which control an engine. I have UART <-> Rs485 converter (this power inverter reads only Rs485 protocol) , so i wrote code in serial protocol (see below). After uploading code on arduino and disconecting arduino from my computer it doesn't send anything (TX led isn't lighted). Maybe some of you know why?
Thank you for any help
#include<util/crc16.h>
#include <SoftwareSerial.h>
SoftwareSerial mySerial(0, 1);
struct DataPacket
{
uint8_t DestinationAddress;
uint8_t function;
uint8_t functioncode;
uint8_t functioncode1;
uint8_t data;
uint8_t data1;
uint16_t CRClow;
uint16_t CRChigh;
} ;
void setup(){
mySerial.begin(9600);
}
void loop(){
DataPacket TxPacket;
TxPacket.DestinationAddress = 0x01;
TxPacket.function = 0x06;
TxPacket.functioncode = 0x01;
TxPacket.functioncode1 = 0x0E;
TxPacket.data = 0x00;
TxPacket.data1 = 0x64;
TxPacket.CRClow = lowByte(MakeCRC(&TxPacket));
TxPacket.CRChigh = highByte(MakeCRC(&TxPacket));
mySerial.write(TxPacket.DestinationAddress);
mySerial.write(TxPacket.function);
mySerial.write(TxPacket.functioncode);
mySerial.write(TxPacket.functioncode1);
mySerial.write(TxPacket.data);
mySerial.write(TxPacket.data1);
mySerial.write(TxPacket.CRClow);
mySerial.write(TxPacket.CRChigh);
}
uint16_t MakeCRC(struct DataPacket *InPacket)
{
uint16_t TempCRC = 0xFFFF;
TempCRC = _crc16_update(TempCRC, InPacket->DestinationAddress);
TempCRC = _crc16_update(TempCRC, InPacket->function);
TempCRC = _crc16_update(TempCRC, InPacket->functioncode);
TempCRC = _crc16_update(TempCRC, InPacket->functioncode1);
TempCRC = _crc16_update(TempCRC, InPacket->data);
TempCRC = _crc16_update(TempCRC, InPacket->data1);
return TempCRC;
}