serial commands - "putc"

30 Oct 2009 . Edited: 31 Oct 2009

I have a question regarding the serial commands.  I need to send a three character command "a,0,6" as a polling call to my serial port.  This command will return a string of 112 bytes that I will write to a buffer.  The compiler does not recognize the "putc" command.  It gives the error "too few argumements in function call".  I should be able to send a single character in hex, decimal or character.  Any ideas on how to fix this?  Here is my code snippet.

int main() 
{
device.baud(115200);

while (1) {
putc(0x61);
wait(0.005);
putc(0x00);
wait(0.005);
putc(0x06);
UART_data_ready  = 1;
n = 0;

30 Oct 2009 . Edited: 31 Oct 2009

I found it helps if you declare which serial port you are sending the command. Here is the correct code that does compile.

//Serial port pin assignment and setup
Serial device(p27, p28);  // tx, rx

while (1) {
device.putc(97);
wait(0.005);
device.putc(0);
wait(0.005);
device.putc(6);
UART_data_ready  = 1;
n = 0;
//********************
wait(0.005);

Now I have to solve the issue with data buffer setup so I can dump data from my device into the RAM.

30 Oct 2009

Note that you can also use character literals instead of numbers:

device.putc('a');

What is the data buffer issue?

30 Oct 2009 . Edited: 31 Oct 2009

The issue is that I have not figured out how to port my old code using commands:

unsigned char      tmp_data[16];
unsigned char       rcvbuf[120];

to the new code.  These are not recognized by the mbed.  They compile but the devices gives the "unhappy LED dance" flashing an error.

Any example code you could suggest would be great.

31 Oct 2009

Can you paste or publish the code? The compiler should certainly accept such buffers.

31 Oct 2009 . Edited: 31 Oct 2009

Here is the code I currently have.

#include "mbed.h"
#include "TextLCD.h"

//Serial port pin assignment and setup
Serial device(p27, p28);  // tx, rx
unsigned char      tmp_data[16];
unsigned char       rcvbuf[120];

int      UART_data_ready;
int      timer_1mS_ready;
int      n;
int      tmp;
int       i;
int RPM;
int PW1;
int DutyCycle;
int CLT;


//LCD 2x20 parallel code pin assignment
TextLCD lcd(p21, p22, p23, p24, p25, p26, p30, 20, 2); // (rs, rw, e, d0, d1, d2, d3, n_column, n_rows)

int column;
int row;


int main() 
{
device.baud(115200);

while (1) {
device.putc(97);
wait(0.005);
device.putc(0);
wait(0.005);
device.putc(6);
UART_data_ready  = 1;
n = 0;
//********************
wait(0.005);

if (UART_data_ready == 0) {        {
//********************************
//get Afr
tmp = rcvbuf[29];
//send text
lcd.locate(0,0);  
lcd.printf("AFR=");

//send data
lcd.printf("%.3f" ,rcvbuf[29]);

}
} else {
lcd.locate(0,0);  
lcd.printf("connection error");
}
}
}

31 Oct 2009 . Edited: 31 Oct 2009

Hi James,

James Novak wrote:
They compile but the devices gives the "unhappy LED dance" flashing an error.

The "unhappy LED dance", otherwise known as the Blue Lights of Death (BLOD), means a runtime error has occurred. If you connect a terminal to the USB serial port, it may often give a diagnostic message too. A common error is trying to pin out a peripheral to incorrect pins (e.g. pins it is not available on).

In your code, you specify:

Serial device(p27, p28);  // tx, rx

Here, the problem is the pins are switched; tx is actually pin 28 and rx pin 27 (see http://mbed.org/nxp/lpc1768/quick-reference), so the code should be:

Serial device(p28, p27);  // tx, rx

This should fix your problem i'd guess.

Simon

31 Oct 2009

thank you for catching that.  I forgot to "handshake" the I/O pins.

Now I can get through the code to the "connection error" on the LCD.  this means I have some other issue.  Time to verify my serial port settings.

31 Oct 2009

Is the default flow control = none?  I can not find this in the documentation.

Also, What is the protocol and voltage for the pin 27/28 serial port?  serial, RS232 and 5V, 12V?

I know I am getting close.

01 Nov 2009

It's 3.3V TTL UART. Default settings are 9600 8N1. I don't think flow control is used, since there are no pins for RTS/DTR signals.

01 Nov 2009

Thank you for the info.  I need a 5V signal into my other device.  time to add a serial chip to the board.  I thought that might be the case.  The TX pin is transmitting according to my scope but nothing is returned.  I will post a solution once I find it.

 

03 Nov 2009

Serial communcations are working properly.  I had to use a 3.3V- 5V serial converter from TI.

 

http://www.mouser.com/Search/Refine.aspx?Keyword=595-SN65C3221DBR