Go Down

Topic: Mods to HardwareSerial to handle 9-bit data (Read 24567 times) previous topic - next topic

marijn

Hi,

I finally came to make my Seatalk project. I started out here and downloaded Nick great code. Thanks Nick.
Then it was time to make the hardware to read the Seatalk data. And things did not compute. I got the wrong commands and it did not work.
Until I looked on a logic analyser (Analog discovery 2, great toy if you can get the edu discount ) the code was inverted. All the schematics I found did invert the signal.
I used: this but this one inverts! So I added an ttl inverter to the rx and tx in fact I did use a 74LS86B a 4 dual EXOR gates. By pulling one input of the EXOR high it inverts the other input on the output. If pulled low it does not invert. Very handy while experimenting with stuff like this. In the schematic R6 should be lower like 1.5K else the gate will not go low.

In the protocoll there is no end character. But after 10mS an other sender can take the line. On the logic analyser the most time between two bytes of the same message was 4.45ms. So I wait for 6mS to process the input buffer.
After 10mS no data the code can send commands to the bus.
It is only the first setup of the code:

Code: [Select]
/*
 * The seatalk receive circuit mut be NON-INVERTING there are many wrong circuits out there. I could only find the wrong versions!
 * I used: http://berreizeta.blogspot.de/2016/10/blog-post.html but this one inverts! So I added an ttl inverter to the rx and tx.
 * in fact I did use a 74LS86B a 4 dual EXOR gates. By pulling one input of the EXOR high it inverts the other input on the output. If
 * pulled low it does not invert. Very handy while experimenting with stuff like this. In the schematic R6 should be lower like 1.5K
 * else the gate will not go low.
 * The code is my first setup but you get my drift
 */
#define SEATALKBUBLEN 20
char seaTalkBufRX[SEATALKBUBLEN]; //longest string found = 16 bytes
char seaTalkBufTX[SEATALKBUBLEN]; //longest string found = 16 bytes

void setup() {

  Serial.begin(115200);
  Serial1.begin(4800,SERIAL_8N1, true); //this is the only init possible if you leave out SERIAL_8N1 you get 8 bit!
  //The seatalk receive circuit mut be NON-INVERTING there are many wrong circuits out there. I could only find the wrong versions!

}

void loop() {
  // put your main code here, to run repeatedly:
  int i;
  int n=0;
  unsigned long t1;
  t1=millis();
  while(1)
  {  
  while(Serial1.available())
  {
    t1=millis();
    i=Serial1.read();
    i=i&0x1ff; //if there is leftover data in the high byte delete this.
    if(i & 0x100)
      Serial.println(' ');
    Serial.print(i,HEX);
    Serial.print(' ');
    seaTalkBufRX[n]=i;
    n++;
  }
  if(millis()-t1>6) //there is no closing char. but the most time between bytes is 4.45ms (on my logic analyser) 6ms should be safe
    DoBufRX();
  if(millis()-t1>=10)
    SendSeatalk();
  }
}

void SendSeatalk(void)
{
  //here goes the send commands. 10ms no data on the bus is bus is free for data
}

ClearBuf(char * buf, int len)
{
  for(int i=0;i<len;i++)
    buf[i]=0;
}

void DoBufRX(void)
{
  //do your rx stuff here
  
}


I hope this helps making your seatalk project.

wbiter

were you able to read data being sent from an actual seatalk device.  Like Martin in the previous post, I also set this one and everything seemed to be working fine, but getting nonsense from the ST 60.  Will try the non-investing approach next time on the boat.

Go Up