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.
9 years, 8 months ago.
Communicating with PC
I'm trying to send a "Hello World!" string to my PC.
I've connected the PINs P4_28,P4_29 and a GND-pin to the PC via a SubD cable.
The settings are Baud: 9600, Data:8, Stop:1, Parity:None
include the mbed library with this snippet
#include "mbed.h" //D1=P4_28 => Tx; D0=P4_29 => Rx Serial pc(D1,D0); //tx, rx int main() { pc.baud(9600); pc.format(8,SerialBase::None,1); wait(1); while(1) { pc.printf("Hello World!"); wait(5); } }
I've put the modem on the same settings, but for some reason I get this response: (I give the received code in decimal)
171 211 210 082 164 139 021 218 116 186 234 003 000
I've got the same result, if I remove the GND-pin.
Thank you for your help in advance.
Question relating to:
![](/media/cache/profiles/u-blox_logo_trans.png.50x50_q85.png)
2 Answers
9 years, 8 months ago.
Hi Abdurrahim,
U-blox C027 Getting start page is https://developer.mbed.org/users/ublox/notebook/u-blox-C027-Getting-Started/
There you can find the schematic: https://developer.mbed.org/media/uploads/ublox/c027_schematics.rar
From schematic you can see that mentioned pins (D1=P4_28 => Tx; D0=P4_29 => Rx) are direct I/O pins of microcontroller, so their voltage level is TTL/CMOS. If you connect them over simple SubD cable (just wires, no converter in between) to PC serial port, this won't work since PC serial port has RS232 levels. Very likely you can damage u-blox or PC serial port (or both).Then you need one RS232 chip (e.g. MAX3232 or similar) between u-blox and PC.
Kind Regards,
Miloje Zecevic
9 years, 8 months ago.
Hi Abdurrahim,
If you want to send characters to your PC use simple code below:
#include "mbed.h" #ifdef TARGET_UBLOX_C027 #include "C027_api.h" #else #error "This example is targeted for the C027 platform" #endif int main() { // open the PC serial port and (use the same baudrate) Serial pc(USBTX, USBRX); pc.baud(115200); while (1) { pc.putc('H'); pc.putc('E'); pc.putc('L'); pc.putc('L'); pc.putc('O'); pc.putc('\n'); wait_ms(1000); } }
This will send serial data from the MCU to your PC. Use USB cable to connect to PC. Connect to the thcdcamX (virtual serial port) using 115200 Baudrate.
Modem has no role in this example. If you want to connect to the module via serial use C027_Modem_Transparent_Serial example. As Miloje said, you can't connect directly to modem's UART as pc's RS232 uses different voltage levels. Could use Raspberry or something similar..
Best regards, Jaka
Thank you for your responses. I've added an RS232 Shield to the modem and now it is working.
What was I thinking.
posted by Abdurrahim Sevay 05 Dec 2014