Hello Sitting and working with a software serial setup.
communication is ok, and in principle, as I receive the correct data, format is just wrong.
Incorrect how.
well it should be understood as.
I sent a request for data.
the device answers.
it looks like that in asci on my serial monitor
AA55001010801050444C333230303132313230393033365D
It should just look like this in HEX
0XAA, 0X55, 0x00 etc.->
what is missing??
#include <SPI.h>
#include <SoftwareSerial.h>
SoftwareSerial mySerial(2, 3); // RX, TX
char sporg_serie_nummer[22]={
0xAA,0x55,0x01,0x00,0x00,0x00,0x10,0x00,0x00,0x01,0x10,0xAA,0x55,0x01,0x00,0x00,0x00,0x10,0x04,0x00,0x01,0x14};
char serienummer_tel=0x00;
char i;
int incomingByte = 0;
void setup()
{
Serial.begin(9600);
mySerial.begin(9600);//115200
}
void loop()
{
serienummer_tel=0x00;
while (serienummer_tel<22)
{
mySerial.print(sporg_serie_nummer[serienummer_tel]);
serienummer_tel++;
}
i=0;
while(i<27) {
if (mySerial.available()>0){
incomingByte = mySerial.read();
Serial.print(incomingByte,HEX); //I have tried various solutions here but it was not right
i++;
}
}
delay(500);
}
Best Kim Jessen
serienummer_tel=0x00;
while (serienummer_tel<22)
If a particular variable is hex, then always use hex with it. If it's a normal number - this seems to be used as a counter - then don't mix hex and normal numbers. By initialising it to a hex number, nobody (including you) can be sure if you really meant to write 0x22 on the second line.
Serial.print(incomingByte,HEX);
The HEX formatting in Serial.print() doesn't pad the leading zeros. Numbers 0x00 to 0x0F will be printed as 0-F and not 00-0F as you might expect.
if(incomingByte<0x10) Serial.print('0');
Serial.print(incomingByte,HEX);
"Quote
Code: [Select]
serienummer_tel=0x00;
while (serienummer_tel<22)
If a particular variable is hex, then always use hex with it. If it's a normal number - this seems to be used as a counter - then don't mix hex and normal numbers. By initialising it to a hex number, nobody (including you) can be sure if you really meant to write 0x22 on the second line."
Yes you are right my mistake.
for the case!
I think you misunderstand what is happening.
I know 100% sure that the unit is transmitting a series of HEX values.
0xAA,0x55,0x00,0x10,0x10,0x80,0x105,0x04,0x44,0xC3,0x33,0x23,0x03,0x03,0x13,0x23,0x13,0x23,0x03,0x93,0x03,0x33,0x65
But I receive it as SCIT values
in ascites I expected to receive this:
UPDL3200121209036]
right now I solved it by loading that coming in into an array.