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.
10 years, 9 months ago.
Serial access under Linux
Hello all,
Another in my continuing saga of getting the sweet spot of settings for serial ports on different OSes...
Today I am using Linux Mint 15 on my AMD A10 workstation, and while I am able to secure a console to the FRDM-K25 board (using /dev/ttyACM0) and able to access the flash drive (ie, I copied over my laser driver firmware), I am unable to raise a response from the board.
First, my code:
#include "mbed.h" #include <stdint.h> #include "PID.h" #define RATE 0.1 AnalogIn sensor(PTA4); // sensor connected to pin 5 DigitalOut laser(PTA12); //Kc, Ti, Td, interval PID controller(1.0, 0.0, 0.0, RATE); PwmOut co(PTC9); Ticker timer; // used for our microsec timing Serial pc(USBTX, USBRX); // serial comms over usb back to console int main() { unsigned short samples[1024]; pc.baud(115200); //Analog input from 0.0 to 3.3V controller.setInputLimits(0.0, 1.0); //Pwm output from 0.0 to 1.0 controller.setOutputLimits(0.0, 1.0); //If there's a bias. controller.setBias(0.0); controller.setMode(AUTO_MODE); //We want the process variable to be 1.7V controller.setSetPoint(0.8); if (pc.readable()); { pc.printf("Press the \"s\" key to start laser test..."); char c = pc.getc(); if((c == 's') && (sensor > 0.0)) { laser = true; } else { pc.printf("ERROR! Check temperature sensor!"); } while (1) { for(int i=0; i<1024; i++) { samples[i] = sensor.read_u16(); wait_ms(1); if (sensor==0.1) { laser = false; co = 1.0; wait(20000); co = 0.0; pc.printf("ERROR! Laser over temperature failure!"); break; } else { controller.setProcessValue(sensor); co = controller.compute(); wait(RATE); } } for(int i=0; i<1024; i++) { pc.printf("%d, 0x%04X\n", i, samples[i]); } } } }
And output from minicom:
Welcome to minicom 2.6.2 OPTIONS: I18n Compiled on Feb 8 2013, 07:03:03. Port /dev/ttyACM0, 15:39:44 Press CTRL-A Z for help on special keys
The port rate is set to 115,200 baud in minicom, with flow control turned off. Ie:
OPTI+-----------------------------------------------------------------------+ Comp| A - Serial Device : /dev/ttyACM0 | Port| B - Lockfile Location : /var/lock | | C - Callin Program : | Pres| D - Callout Program : | | E - Bps/Par/Bits : 115200 8N1 | | F - Hardware Flow Control : No | | G - Software Flow Control : No | | | | Change which setting? | +-----------------------------------------------------------------------+
However, even though the program is supposed to herald with the statement "Press the "s" key to start laser test..." even starting minicom, making sure all settings are correct, and resetting the board still brings no response.
Do anyone have any thoughts or suggestions?
Thanks!
1 Answer
10 years, 9 months ago.
pc.readable() only gets true when there's data available. "Press the \"s\" key to start laser test..." would only be displayed after receiving something on the serial port. I've made some changes to your code (not tested, but worth trying).
test
#include "mbed.h" #include <stdint.h> #include "PID.h" #define RATE 0.1 AnalogIn sensor(PTA4); // sensor connected to pin 5 DigitalOut laser(PTA12); //Kc, Ti, Td, interval PID controller(1.0, 0.0, 0.0, RATE); PwmOut co(PTC9); Ticker timer; // used for our microsec timing Serial pc(USBTX, USBRX); // serial comms over usb back to console unsigned short samples[1024]; void setup() { pc.baud(115200); //Analog input from 0.0 to 3.3V controller.setInputLimits(0.0, 1.0); //Pwm output from 0.0 to 1.0 controller.setOutputLimits(0.0, 1.0); //If there's a bias. controller.setBias(0.0); controller.setMode(AUTO_MODE); //We want the process variable to be 1.7V controller.setSetPoint(0.8); pc.printf("Press the \"s\" key to start laser test..."); } int main() { setup(); if (pc.readable()); { char c = pc.getc(); if((c == 's') && (sensor > 0.0)) { laser = true; } else { pc.printf("ERROR! Check temperature sensor!"); } while (1) { if (laser){ for(int i=0; i<1024; i++) { samples[i] = sensor.read_u16(); wait_ms(1); } if (sensor==0.1) { laser = false; co = 1.0; wait(20000); co = 0.0; pc.printf("ERROR! Laser over temperature failure!"); break; } else { controller.setProcessValue(sensor); co = controller.compute(); wait(RATE); } } for(int i=0; i<1024; i++) { pc.printf("%d, 0x%04X\n", i, samples[i]); } } } }