Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
8 years, 1 month ago.
Serial.attach in OS 5
Hi, before OS5 in libraries you attached a serial IRQ this way
attach(this, &MyClass::rxIrqBuf, RxIrq);
how do you do it in OS5.2? I can see the source code bellow, but if someone could give an example
void attach(T *obj, void (T::*method)(), IrqType type=RxIrq) {}
Thank you
2 Answers
5 years, 10 months ago.
I would also like to know how to make these changes.
Re: Sam Groves buffered serial:
https://os.mbed.com/users/sam_grove/code/Buffer/
This line throws a 'depreciated' warning.
RawSerial::attach(this, &BufferedSerial::rxIrq, Serial::RxIrq);
What would I need to replace this with to work with Mbed 2 ?
Hello Paul,
I dig my codes and found something. Please check, modify and verify for yourself..
This is header file (May be not complete)
#ifndef _RF_H_ #define _RF_H_ #define RF_POWER_PIN PB_10 #define RF_BAUDRATE 38400 // RF Serial Pins #define RF_TX PA_11 // RF module Tx Pin (Serial6) #define RF_RX PA_12 // RF module Rx Pin (Serial6) // Coordinator Address #define COORDINATOR_ADDRESS_1 255 // WSN coordinator address 1st byte (0xFF) #define COORDINATOR_ADDRESS_2 255 // WSN coordinator address 2nd byte (0xFF) #define CR 13 // "\r" ASCII code #define EQUAL 61 // "=" ASCII code class RF { public: RF(); ~RF(); volatile bool rfRxInterruptComplete; // RF Initializaton void powerUpRF(void); void initRF(int _baudrate); // RF Interrupt Controls void rfRxISR(void); void startRxInterrupt(void); void stopRxInterrupt(void); char *readRFRxBuffer(void); void clearRFRxBuffer(void); void send_to_coordinator(char *_data); private: DigitalOut *powerPin; RawSerial *rfSerial; volatile char rfRxBufferChar; char rfRxBuffer[256]; volatile uint8_t rfRxBufferCounter; }; #endif
This is cpp
#include "rf.h" RF::RF() { powerPin = new (RF_POWER_PIN, 0); rfSerial = new RawSerial(RF_TX, RF_RX); rfRxBufferCounter = 0; rfRxInterruptComplete = false; } RF::~RF() { delete powerPin; delete rfSerial; } void RF::powerUpRF(void) { powerPin->write(1); wait_ms(50); } void RF::rfRxISR(void) { rfRxBufferChar = rfSerial->getc(); if (rfRxBufferChar != '\r') { rfRxBuffer[rfRxBufferCounter] = rfRxBufferChar; rfRxBufferCounter++; } else if (rfRxBufferChar == '\r') { rfSerial->attach(NULL, Serial::RxIrq); rfRxBufferCounter = 0; rfRxInterruptComplete = true; } } void RF::initRF(int _baudrate) { rfSerial->baud(RF_BAUDRATE); rfSerial->attach(callback(this, &RF::rfRxISR), Serial::RxIrq); } void RF::stopRxInterrupt(void) { rfSerial->attach(NULL, Serial::RxIrq); } void RF::startRxInterrupt(void) { rfSerial->attach(callback(this, &RF::rfRxISR), Serial::RxIrq); } char *RF::readRFRxBuffer(void) { return rfRxBuffer; } void RF::clearRFRxBuffer(void) { memset(rfRxBuffer, 0, sizeof(rfRxBuffer)); } void RF::send_to_coordinator(char *_data) { rfSerial->putc(COORDINATOR_ADDRESS_1); rfSerial->putc(COORDINATOR_ADDRESS_2); rfSerial->putc(EQUAL); rfSerial->puts(_data); rfSerial->putc(CR); }
Regards :)
posted by 16 Feb 20195 years, 10 months ago.
Hello;
Try something like below (Edit it for your code)
rfSerial->attach(callback(this, &RF::rfRxISR), Serial::RxIrq);
Thanks Kamil,
Assuming I have this correct,
RawSerial->attach(callback(this, &BufferedSerial::RawSerialRxISR), Serial::RxIrq);
I get this error:
Error: Expected an identifier in "ESP8266/ATParser/BufferedSerial/BufferedSerial.cpp", Line: 35, Col: 15
posted by 15 Feb 2019Hello Paul,
Because RawSerial
is a class raher than a pointer to a RawSerial
object try:
RawSerial::attach(callback(this, &BufferedSerial::RawSerialRxISR), Serial::RxIrq);
and make sure that a void RawSerialRxISR()
method is defined for the BufferedSerial
class.
Seem to be getting closer Zoltan :)
But I'm not very good with code.
snip from BufferedSerial.h
class BufferedSerial : public RawSerial { private: MyBuffer <char> _rxbuf; MyBuffer <char> _txbuf; uint32_t _buf_size; uint32_t _tx_multiple; void RawSerialRxISR(); // put this here ? void rxIrq(void); void txIrq(void); void prime(void); public:
Now I get this:
Error: Undefined symbol BufferedSerial::RawSerialRxISR() (referred from ../../build/ESP8266/ATParser/BufferedSerial/BufferedSerial.MAX32630FTHR.o).
Can't believe that no one else has seen this issue, is Serial interrupt function not used any more? Whilst it does work okay, I don't like to see warnings when I compile and this is the only one I get. I suppose I can't complain compared with the 150 or so warnings on OS5.
posted by 16 Feb 2019Never mind Paul, It's difficult to hold my nerv with mbed too :)
After importing the ATParser
library and taking a closer look I'd suggest to replace
RawSerial::attach(this, &BufferedSerial::rxIrq, Serial::RxIrq);
with
RawSerial::attach(callback(this, &BufferedSerial::rxIrq), Serial::RxIrq);
both in the BufferedSerial::BufferedSerial
construcor and in the BufferedSerial::prime
function.
No warnings should be reported after that.
Not sure if this is posting under the correct part, but both suggestions were correct to sort this out.
Zoltan, I did the two changes as you said, (void RawSerialRxISR(); put this here ? was't needed). But the BufferedSerial::prime, I had to change rxIrq to txIrq and RxIrq to TxIrq and now I get no warnings on a full Compile All using MBED-DEV (rev.187, current) with a STM32L432 board and it works exactly as I would expect it to :) :) :)
I think this is the first time I have seen that for some years. My confidence is now firmly back with Mbed.
This must be an Mbed record!!
posted by 16 Feb 2019
-
posted by Zoltan Hudak 15 Feb 2019Sorry for the late response. The following should work:
only 2 years late :-) but thank you for your effort
posted by Pavel S 19 Feb 2019