It says:
RX, Primarily used as UART RX, but can also be used as a digital GPIO or PWM.
TX,Primarily used as UART TX, but can also be used as a digital GPIO or PWM.
But I dont see any pin mapping to use RX/TX. So am I out of luck here ?
I do not know precisely why you need a interrupt on RX pin.
But if you need a interruption when you have data on RX pin you can use the following function: serialEvent()
Is there a function for generating interupt when there is data to the serial port?
I know that there is a low level such as USART1_IRQHandler but if there’s an API for that?
This is an example for Mbed:
#include "mbed.h"
DigitalOut led1(LED1);
DigitalOut led2(LED2);
Serial pc(USBTX, USBRX);
void callback() {
// Note: you need to actually read from the serial to clear the RX interrupt
printf("%c\n", pc.getc());
led2 = !led2;
}
int main() {
pc.attach(&callback;);
while (1) {
led1 = !led1;
wait(0.5);
}
}
To answer your question. Since the RX buffer for Serial1 is fixed at 64 bytes, and I don’t know exactly when I will be receiving this serial data.The serial data will come from another device giving info like:
Level 1 sensor value is 1022
Requested IP address is 192.168.1.23
How fast these happen is another issue, so even though each line may be <64 bytes, if it sends 2 messages back to back is where the trouble comes in. To further complicate things I have my own SPI & I2c devices to talk to. Which limits the amount of time I can sit in a while loop waiting for serial data.
This is the reason I am trying to see if there is another / better way around the limit 64 byte issue. If we could increase Serial1’s buffer this would allow me more time to get back to it.
@mikemoy, what would be ideal would be a user-specified buffer for Serial and Serial1. However, the Serial object is instantiated by the system firmware prior to running user code so a buffer had to be specified already. You can increase the system buffer size but only if you compile using a local toolchain.
I am not quite sure what they mean by "…allocate its own buffers for Serial and USBSerial1"
When Serial is the USB connection, so what then is USBSerial ?
@mikemoy, you are correct. acquireSerialBuffer() can redirect the serial buffer to a user specified buffer. However, this is not applicable to the UART serial ports such as Serial1 on the Photon.