cancel
Showing results for 
Search instead for 
Did you mean: 

ST7580 USART with Arduino

patramirez25
Associate
Posted on February 01, 2013 at 06:02

Hello,

I'm having a problem interfacing my ST7580 using Arduino Mega USART. And I think I already broke 2 pcs of IC and I cannot afford to lose some more.

Please help me code to PING, Read/Write MIB and send even simple PHY data over the powerline.

The Arduino code I used is here....

/* Arduino Code � ST7580 Transceiver Board

Code Consideration: 

Not sure if syntax and arguments in User Manual work with all types of microcontroller. Just to be sure, per byte transmission will be used. 

For fields with >1 byte, endianness is assumed to start with byte index 0, which is the logical thing to do.

Code Author: Patth Rick L. Ramirez, BS ECE 2008-11684

*/

//GPIO Pin Assignments

&sharpdefine  aT_REQ  2

&sharpdefine  aBR0    3

&sharpdefine  aBR1    4

&sharpdefine  aPL_TX_ON  22

&sharpdefine  aPL_RX_ON  24

&sharpdefine  aPLC_RESETN  26

//Local UART/Serial Pin Assignments

&sharpdefine  uC_TX  14 //RxD of ST7580 ; USART TX3

&sharpdefine  uC_RX  15 //TxD of ST7580 ; USART RX3

//Analog Pin Assignments

//&sharpdefine  aCL_ADC 12   //hardware available but may not be necessary

//&sharpdefine  aPA_ADC 13

/*Initialize variables*/

int avail = 0;

        byte inBUF = 0x00; //general purpose byte storage

word inSTAT = 0x0000; //status message 2 bytes, index 0 should always be 3Fh

byte inSTX = 0x00;

byte inLEN = 0x00; // byte length of data field

byte inCC= 0x00;

byte inCSUM_LSB = 0x00; //checksum field is sent LSByte first

byte inCSUM_MSB = 0x00;

byte inDATA_0 = 0x00;

byte inDATA_1 = 0x00;

byte inDATA_2 = 0x00;

byte inDATA_3 = 0x00;

byte inDATA_4 = 0x00;

byte inDATA_5 = 0x00;

byte inDATA_6 = 0x00;

byte inDATA_7 = 0x00;

byte inDATA_8 = 0x00;

byte inDATA_9 = 0x00;

byte inDATA_10 = 0x00;

byte inDATA_11 = 0x00;

byte inDATA_12 = 0x00;

byte inDATA_13 = 0x00;

byte inDATA_14 = 0x00; //max number of data bytes as set by user == 16

byte inDATA_15 = 0x00;

void GPIO_Init(void){

/*Inputs*/

pinMode(aPL_TX_ON,INPUT);

pinMode(aPL_RX_ON,INPUT);

pinMode(aPLC_RESETN,INPUT);

/*Outputs*/

pinMode(aT_REQ,OUTPUT);

pinMode(aBR0,OUTPUT);

pinMode(aBR1,OUTPUT);

/*Initial Values*/

digitalWrite(aBR0,LOW); //set ST7580�s UART Baud rate to 9600

digitalWrite(aBR1,LOW);

digitalWrite(aT_REQ,HIGH); //set to LOW if requesting transmission to ST7580

} //GPIO_Init();

void send_START(byte outSTX, byte outLEN, byte outCC){

Serial3.write(outSTX);

        Serial.println(''STX field is sent.'');

        digitalWrite(aT_REQ, HIGH); //bring back to default HIGH as soon as STX byte is received by ST7580

        Serial3.write(outLEN);          //byte length of data field

Serial3.write(outCC);

}//e.g. send_START(0x02, 0x05, 0x2C); 

void send_PING_DATA(byte PDATA){

Serial.println(''Pinging the ST7580 device...'');

Serial3.write(PDATA); //make it a 3-byte data ping

Serial3.write(PDATA);

        Serial3.write(PDATA);

}//e.g. send_PING_DATA(0xAA);         //CC for PingRequest is 2Ch

void send_CSUM(byte outCSUM_LSB, byte outCSUM_MSB){

Serial3.write(outCSUM_LSB); //checksum is sent LSB first

        Serial3.write(outCSUM_MSB);

        Serial.println(''Checksum bytes sent.'');

}

void setup(){

/*Initialize GPIO ports*/

GPIO_Init();

/*Set-up serial port 0 at 9600 bps � for printing data to the serial monitor*/

Serial.begin(9600);

/*Initialize Serial Port 3 at 9600 bps, 8 data bits, 1 stop bit*/

Serial3.begin(9600);

     Serial.println(''Trying to PING ST7580 in'');

Serial.println(''3...'');

delay(1000);

Serial.println(''2...'');

delay(1000);

Serial.println(''1...'');

delay(1000);      

}

void loop(){

  delay(1000);

  

  while (Serial3.available() > 0){

      inBUF = Serial3.read();

      Serial.println(''Flushing FIRST.'');

  }  //flush unnecessary receive buffer bytes

  

  do{

  digitalWrite(aT_REQ, LOW);

  Serial.println(''Requesting transmission to ST7580.'');

  delay(150);

  inBUF = Serial3.read();

  inSTAT = inBUF;

  delay(10);

  inBUF = Serial3.read();

  inSTAT = inSTAT | (inBUF<<8);

  delay(10);

  Serial.println(inSTAT,HEX);

  if (inSTAT == 0x093F)

    Serial.println(''ST7580 is available.'');

  else

    Serial.println(''ST7580 is busy.'');

  } while (inSTAT != 0x093F);

    

  delay(30);                  //IMPT Why?

  

  send_START(0x02,0x06,0x2C);  //PING Request

  send_PING_DATA(0xCB);

  send_CSUM(0x93,0x02);

  delay(30);

  //inBUF = Serial3.read(); // has stray FEh?

  while (Serial3.available() > 0){

    inBUF = Serial3.read();

    delay(50);

    Serial.println(inBUF,HEX);

    if ((inBUF==0x06) || (inBUF==0x15))

      Serial.println(''Acknowledgement message received.'');

    else

      Serial.println(''Received what byte?'');

   } 

}//loop()        

Thank you very much to those who can help me. I hope you guys can I really need help. T_T

#arduino #st7580
1 REPLY 1
bendeniz_558
Associate
Posted on April 29, 2015 at 19:03

Hello,

I am working on st7570 using Ardunio UNO.But I can t find this c library(header and source code) everywhere.Maybe you can help me this issue.

Regards,

TOLGA