I think I'm doing this right. I want to talk to my modbus gizmo. First I wired it
up and used a vendor supplied utility to make sure it works (it did as to rule
out faulty hardware). I setup a very simple sketch to see if I can get the output
of one register, if all is good; then go from there.
//+-------+-------+-------+-------+-------+-------+-------+-------+
//| 01 | 03 | Ref Hi| Ref Lo| Num Hi| Num Lo| CRC Lo| CRC Hi|
//+-------+-------+-------+-------+-------+-------+-------+-------+
// slave func |<----2 bytes-->|<----2 bytes-->|<----2 bytes-->|
// 01 03 40 00 00 08 (read in 40007) CRC CRC
// 0x09C45 is the address for register 40007
// 0xA17C is the CRC for the byte string below. low byte first according to modbus rtu frames.
// 01 is the slave address, 0x03 is the modbus function - simple read. in my case one register.
byte message[] = {0x01,0x03,0x9C,0x45,0x00,0x01,0x7C,0xA1};
void setup() {
Serial.begin(9600); //Set Serial Baud Rate for Modbus
pinMode(2,OUTPUT); //Pin 3 will used for communicating to Max485 Chip
}
void loop() {
char inBound = 0;
pinMode(2,HIGH); //Turn on the max485 chip to transmit. Pin 1 is TX
//Wired to pin 2. Pin 3 on max485 is also connected to pin 2
Serial.write(message,sizeof(message));
pinMode(2,LOW); //Turn off the chip to receive pin 1.
if (Serial.available()> 0 ){
inBound = Serial.read();
Serial.println(inBound,HEX); //Output pin 4 on max485
}
delay(1000); //Wait 1 seconds for Modbus to respond }
Of course life isn't that simple: attached is the output of my logic analyzer. Seems like I'm talking to the Max485 ok and it's talking to the gizmo, but something is amiss. Another set of eyes might show me what what I'm missing.
Thanks.
A line
B line (notice how what on TX matches) so I'm at least sending the data correctly)
TX line
RX line
Serial Write questions
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- adafruit_support_mike
- Posts: 67446
- Joined: Thu Feb 11, 2010 2:51 pm
Re: Serial Write questions
You've given us a good rundown of the background, but forgot to tell us the problem. What is the device doing that you don't expect, or not doing that you do expect?
- Renate
- Posts: 291
- Joined: Tue Nov 13, 2012 3:21 pm
Re: Serial Write questions
I don't know what/how you are monitoring those signals.
Looking at the bottom trace, I'd eyeball it as coming back at you at 38.4 kbaud.
Why don't you try that?
Looking at the bottom trace, I'd eyeball it as coming back at you at 38.4 kbaud.
Why don't you try that?
Please be positive and constructive with your questions and comments.