Pages: [1]   Go Down
Author Topic: RS232 handshaking  (Read 299 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

This is part of my code

Quote

#include <LiquidCrystal.h>
LiquidCrystal lcd(8,9,4,5,6,7);
const int sw1 = 3;
int zn;
int x=0;

void ini_comm(){
  Serial.end();    
  Serial.begin(2400);  
  UCSR0C = ( UCSR0C & ~_BV(UPM00) | _BV(UPM01) );
} //UPM01=1 --> Parity on  UPM00=0-->Even  

void setup() {
  lcd.begin(16, 2);
  pinMode(sw1, INPUT);
  digitalWrite(sw1,HIGH);
  lcd.print("1 start  ");
  lcd.setCursor(0, 1);
 }

void loop(){
  if(digitalRead(sw1)==LOW)
  {
    delay(1000);
    lcd.clear();
    ini_comm();     // ini comm
    Serial.write(0xF4);
    Serial.write(0x03);
    Serial.write(0x51);
    Serial.write(0x0A);
    Serial.write(0xAC);
  }
  if (Serial.available() > 0) {
    zn = Serial.read();
    lcd.print(zn,HEX);
    lcd.print(' ');
  }
}



I don't have reply on LCD ( terminal show repply ).
It looks like RX start with little latency. Why ?


Logged

SE USA
Offline Offline
Faraday Member
**
Karma: 41
Posts: 3783
@ssh0le
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

maybe cause you delay for a second, which stops your whole program?
Logged


Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Delay is only for switch. ( no repeating ini comm ).
It does not matter for reciving !!!!!!!!
  ini_comm();     // ini comm
    Serial.write(0xF4);
    Serial.write(0x03);
    Serial.write(0x51);
    Serial.write(0x0A);
    Serial.write(0xAC);

When I send F4 03 51 0A AC I see response on terminal but don't see on LCD !!!
Logged

Pages: [1]   Go Up
Jump to: