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.
7 years ago.
whay am I getting Error: Identifier "SERIAL_TX" and "SERIAL_RX" is undefined?
Identifier "SERIAL_TX" and "SERIAL_RX" compilation error
As I am trying to compile the code below, I am getting these error. Does anybody can kindly tell me what I did incorrect or tell the me step to include the serial port library?
Here are the errors
Error: Identifier "SERIAL_TX" is undefined in "main.cpp", Line: 4, Col: 12 Error: Identifier "SERIAL_RX" is undefined in "main.cpp", Line: 4, Col: 23
#include "mbed.h" #include <stdio.h> Serial pc(SERIAL_TX, SERIAL_RX); LocalFileSystem local("local"); // Create the local filesystem under the name "local" DigitalOut led(LED1); AnalogIn analog_value(A0); int main() { FILE *fp = fopen("/local/out.txt", "w"); // Open "out.txt" on the local file system for writing int i = 1; float meas_r; float meas_v; pc.baud(9600); pc.printf("Welcome To Temperature Logger... !\n\r"); while (1) { meas_r = analog_value.read(); // Read the analog input value (value from 0.0 to 1.0 = full ADC conversion range) meas_v = meas_r * 2800; // Converts value in the 0V-3.3V range pc.printf("measure = %f = %.0f mV\n\r", meas_r, meas_v); wait(1); // 1 second led = !led; // Toggle LED pc.printf("This program runs since %d seconds.\n\r", i++); fprintf(fp, "Hello World!"); fclose(fp); } }
What happens if you replace SERIAL_TX/RX with USBTX and USBRX?
posted by Russell Bateman 04 Nov 2017It would seem that SERIAL_TX and SERIAL_RX are undefined for your target. The pin name definitions should be included automatically, should not have to do anything else. You can look up the pin map for your target in the mbed source code. and maybe get an idea why they were not included. Those arguments are simply type PinName, so you can give it regular PinNames like PA_1, PA_2, etc. For ST targets these are defined in a file called PinNames.h with simple definitions like this: