https://www.st.com/en/ecosystems/x-nucleo-plm01a1.html MBED driver for the ST7580 IC.
Revision 1:edbcde816013, committed 2019-04-20
- Comitter:
- Arthrik
- Date:
- Sat Apr 20 20:18:49 2019 +0000
- Parent:
- 0:e88514a784bb
- Commit message:
- Data reception now works.; Updated the example code.; It still needs some work, but it's usable
Changed in this revision
diff -r e88514a784bb -r edbcde816013 ST7580.cpp --- a/ST7580.cpp Mon Apr 15 06:41:00 2019 +0000 +++ b/ST7580.cpp Sat Apr 20 20:18:49 2019 +0000 @@ -4,7 +4,7 @@ { this->_rcv_data_idx = 0; this->_rcv_data_offset = 0; - this->_step = 0; + this->_rcv_payload_len = 255; _plm_t_req = new DigitalOut(t_req); _plm_reset = new DigitalOut(reset); @@ -19,7 +19,7 @@ void ST7580::init() { - printf("PLM INIT START\n"); + //printf("PLM INIT START\n"); _plm_t_req->write(1); @@ -29,7 +29,7 @@ this->wait_reset(); - printf("PLM INIT DONE\n"); + //printf("PLM INIT DONE\n"); } void ST7580::send_frame(unsigned char *msg, int msg_length) @@ -67,8 +67,8 @@ _plm_t_req->write(0); - this->wait_status(); - + //this->wait_status(); + wait_ms(ST7580_TSR); //p.18 de la doc ST7580 _plm_uart->printf((const char*)full_data); @@ -77,48 +77,55 @@ // _plm_uart->putc(full_data[i]); //} _plm_t_req->write(1); - printf("SENT DATA\n"); + //printf("SENT DATA\n"); } void ST7580::wait_status() { - while (this->_rx_char != ST7580_STX_STATUS); + while (_rx_char != ST7580_STX_STATUS); } void ST7580::wait_reset() { - while (this->_rx_char != CMD_RESET_IND); + while (_rx_char != CMD_RESET_IND); } void ST7580::reset_reception_buffer() { - this->_step = 0; - this->_rcv_data_idx = 0; - memset((char *)this->_rcv_data, 0, sizeof(char) * sizeof(this->_rcv_data)); //Reset reception buffer + _rcv_payload_len = 255; + _rcv_data_idx = 0; + memset((char *)_rcv_data, 0, sizeof(_rcv_data)); //Reset reception buffer } void ST7580::rx_complete() { - this->_usr_callback((unsigned char *)this->_rcv_data, this->_rcv_data_idx); //callback into the user app + //printf("%s\n", (unsigned char *)this->_rcv_data); + this->_usr_callback((unsigned char *)_rcv_data + 7, _rcv_payload_len); //callback into the user app, trims the PLC data; this->reset_reception_buffer(); - //printf("OVERFLOW: RESET\n"); } void ST7580::rx_callback() { - if (this->_rcv_data_idx >= 512) this->reset_reception_buffer(); - this->_rx_char = _plm_uart->getc(); - if (this->_step > 9) + _rx_char = _plm_uart->getc(); + _rcv_data[_rcv_data_idx] = _rx_char; + _rcv_data_idx++; + if (_rcv_data[0] == ST7580_STX_02) //If this is a start condition { - if (this->_rx_char == '%') + if (_rcv_data_idx > 1) { - this->rx_complete(); - } - else - { - this->_rcv_data[this->_rcv_data_idx++] = this->_rx_char; - this->_rcv_data_idx++; + _rcv_payload_len = _rcv_data[1]; + if (_rcv_payload_len < 5) + { + this->reset_reception_buffer(); + } + if (_rcv_data_idx >= _rcv_payload_len) + { + this->rx_complete(); + } } } - this->_step++; -} \ No newline at end of file + else + { + this->reset_reception_buffer(); + } +}
diff -r e88514a784bb -r edbcde816013 ST7580.h --- a/ST7580.h Mon Apr 15 06:41:00 2019 +0000 +++ b/ST7580.h Sat Apr 20 20:18:49 2019 +0000 @@ -12,13 +12,18 @@ * \brief ST7580 driver * * here is a minimal example: -* -* ST7580 shield(D8, D2, D13, D7); +* void callback_function(unsigned char *data, int payload_length) +* { +* //Do what you want with the data +* } +* int main() { +* ST7580 shield(D8, D2, D13, D7, callback_function); * shield.init(); * wait(1); * while(1) { * shield.send_frame("Hello world!"); * } +* } */ class ST7580 { @@ -43,7 +48,6 @@ */ void init(); void send_frame(unsigned char *msg, int msg_length); - //void receive_frame(); private: void wait_status(); @@ -54,14 +58,14 @@ void (*_usr_callback)(unsigned char *, int); volatile unsigned char _rx_char; - volatile unsigned char _rcv_data[512]; + volatile unsigned char _rcv_data[255]; volatile int _rcv_data_idx; volatile int _rcv_data_offset; - volatile int _step; + volatile int _rcv_payload_len; DigitalOut *_plm_t_req; DigitalOut *_plm_reset; RawSerial *_plm_uart; }; -#endif \ No newline at end of file +#endif
diff -r e88514a784bb -r edbcde816013 ST7580_codes.h --- a/ST7580_codes.h Mon Apr 15 06:41:00 2019 +0000 +++ b/ST7580_codes.h Sat Apr 20 20:18:49 2019 +0000 @@ -172,4 +172,4 @@ #define ST7580_MOD_QPSK_COD (5 << 4) /* Q-PSK coded modulation */ #define ST7580_MOD_BPSK_COD_PNA (7 << 4) /* B-PSK coded with Peak \ Noise Avoidance modulation */ -#define ST7580_ZC (1 << 7) /* Zero crossing synchronization */ \ No newline at end of file +#define ST7580_ZC (1 << 7) /* Zero crossing synchronization */