I'm trying to get some charaters from PC using UART but I couldn't. instead I just can see same repeated strings on the serial terminal that I sent out just before. I have tried all the ways that I can but I couldn't find out any solutions.
Tx and opening ttyb: is working fine because I can see the strings "ttyb opend" from write(serial_fd,"ttyb opend", 10);
using MQX 3.8.1, Kinetis K10 CPU on 96Mhz core clock.
Please help.
settings and code are as below.
in user_config.h
#define BSPCFG_ENABLE_TTYB 1
in main.c
if((serial_fd = fopen("ttyb:",(pointer) ( IO_SERIAL_TRANSLATION)))==NULL){
printf("ttyb open failed!\n");
}else{
write(serial_fd,"ttyb opend", 10);
}
while(1)
{
_time_delay(100);
if (fstatus( serial_fd )) {
tmp = fgetc(serial_fd);
fputc((char)tmp,serial_fd);
}
}
terminal output
petttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opetttyb opettty
thanks
Hi freewill,
Have you updated your equivalent twrk60n512.h (BSP device header file) to have ttyb the default IO Channel?
Reference the "<-- CHANGE to" comments below:
/*
* Other Serial console optionsdo not forget to enable BSPCFG_ENABLE_TTY define if changed)
* "ittyf:" OSJTAG-COM interrupt mode
* "ttyd:" TWR-SER polled mode
* "ittyd:" TWR-SER interrupt mode
* "iodebug:" IDE debug console
** MGCT: <option type="string" maxsize="256" quoted="false" allowempty="false"/>
*/
#ifndef BSP_DEFAULT_IO_CHANNEL
#if BSPCFG_ENABLE_TTYD <-- CHANGE to TTYB
#define BSP_DEFAULT_IO_CHANNEL "ttyd:" <-- CHANGE to ttyb:
#define BSP_DEFAULT_IO_CHANNEL_DEFINED
#else
#define BSP_DEFAULT_IO_CHANNEL NULL
#endif
#else
/* undef is for backward compatibility with user_configh.h files which have already had it defined */
#undef BSP_DEFAULT_IO_CHANNEL_DEFINED
#define BSP_DEFAULT_IO_CHANNEL_DEFINED
#endif
Regards,
David
Thanks David,
yes I already changed that you mentioned but not working.
here is my setting.
#ifndef BSP_DEFAULT_IO_CHANNEL
#if BSPCFG_ENABLE_TTYB
// #define BSP_DEFAULT_IO_CHANNEL "ttya:" /* OSJTAG-COM polled mode */
#define BSP_DEFAULT_IO_CHANNEL "ttyb:" /* OSJTAG-COM polled mode */
#define BSP_DEFAULT_IO_CHANNEL_DEFINED
#else
#define BSP_DEFAULT_IO_CHANNEL NULL
#endif
#endif
the UART Tx is working fine but Rx is always not working.
have you any experiece like this problem?
I don't have any ideas to try more.
thanks.
Hi David,
thank you for your quick reply.
I applied that you provide, but Rx is still not working.
If I remove the write as below, there was no input and output. even if I press keyboard.
// write(serial_fd,"ttyb opend", 10);
once I add the write setence, it is always spit out same strings.
BR,
freewill
Hi freewill,
have you checked that correct IO-pins are activated in function init_gpio.c:_bsp_serial_io_init.
/* Setup GPIO for UART devices */
switch (dev_num)
{
case 1: << This is for TTYB
pctl = (PORT_MemMapPtr)PORTC_BASE_PTR;
if (flags & IO_PERIPHERAL_PIN_MUX_ENABLE)
{
/* PTC3 as RX function (Alt.3) + drive strength */
pctl->PCR[3] = 0 | PORT_PCR_MUX(3) | PORT_PCR_DSE_MASK;
/* PTC4 as TX function (Alt.3) + drive strength */
pctl->PCR[4] = 0 | PORT_PCR_MUX(3) | PORT_PCR_DSE_MASK;
}
...
~Mark
thanks everybody
as I have tried all the ways you suggested, but still I have same problem.
so I am going to write my own UART driver. because I don't have much time.
support from you guys was great and really helpful.
thank you very much.
Kevin. P
In general interrupt mode is better as you don't waste time polling in your application. However if you are primarily transporting data over serial and you have very high throughput polling can be more efficient as you don't have the over head of interrupt processing.