This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Hi,
My board is TM4C123GH6PGE. What i'm tring to achieve is to send hex commands to another controller throw the UART. Currently, i can send and receive data throw UART0 (USB cable) while connected to the PC. With a simple serial port teminal app' i can see the messages that i send from the controller to the PC.
I looked over the uart_echo.c example and i tried to change all of the UART0 references to UART3, and also initiate the relevent pins. After that i connected the Rx, Tx, GND and VCC(3.3) pins to an TTL to RS232 convertor because as i know, RS232 protocol doesn't work with 3.3v.
Now that my system is connected to the PC i tried to send messages between the PC and the controller but now my PC doesn't get anything from the controller.
My code for sending to PC is:
UARTCharPut(UART3_BASE, 0xAB);
My final achievement is to send data from TI controller to anothe controller, by i prety sure that if it work with the PC i will work with another controller (non TI).
Thank You.
Hi Luis and Markel,
Thank you for your response.
First, the 0xAB what just an example for the hex string that i need to send. My actual strings are like: 0x08003024AFC and the meaning of this string is to set a command to another driver (non TI product).
As i continue working with uart_echo.c example i changed the sending message to: UARTCharPut(UART3_BASE, 49);. I put this line inside the infinite while so from my understanding the controller should write "1" to serial without stop.
This is not working. What is working is when i write to serial port terminal in my PC some hex values, the TI controller transmits back hex values but not the same.
So i looked in the example again for the UARTIntHandler function, but i didn't understand who is the variable that holds the incomming message.
The modifies code is attached, and i looked again to my TTL to RS232 convertor and it looks ok.
//***************************************************************************** // // uart_echo.c - Example for reading data from and writing data to the UART in // an interrupt driven fashion. // // Copyright (c) 2011-2013 Texas Instruments Incorporated. All rights reserved. // Software License Agreement // // Texas Instruments (TI) is supplying this software for use solely and // exclusively on TI's microcontroller products. The software is owned by // TI and/or its suppliers, and is protected under applicable copyright // laws. You may not combine this software with "viral" open-source // software in order to form a larger program. // // THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL FAULTS. // NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT // NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. TI SHALL NOT, UNDER ANY // CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL // DAMAGES, FOR ANY REASON WHATSOEVER. // // This is part of revision 2.0.1.11577 of the DK-TM4C123G Firmware Package. // //***************************************************************************** #include <stdint.h> #include <stdbool.h> #include <stdio.h> #include "inc/hw_ints.h" #include "inc/hw_memmap.h" #include "driverlib/debug.h" #include "driverlib/fpu.h" #include "driverlib/gpio.h" #include "driverlib/interrupt.h" #include "driverlib/sysctl.h" #include "driverlib/uart.h" #include "driverlib/rom.h" #include "grlib/grlib.h" #include "drivers/cfal96x64x16.h" //***************************************************************************** // //! \addtogroup example_list //! <h1>UART Echo (uart_echo)</h1> //! //! This example application utilizes the UART to echo text. The first UART //! (connected to the USB debug virtual serial port on the evaluation board) //! will be configured in 115,200 baud, 8-n-1 mode. All characters received on //! the UART are transmitted back to the UART. // //***************************************************************************** //***************************************************************************** // // The error routine that is called if the driver library encounters an error. // //***************************************************************************** #ifdef DEBUG void __error__(char *pcFilename, uint32_t ui32Line) { } #endif //***************************************************************************** // // The UART interrupt handler. // //***************************************************************************** void UARTIntHandler(void) { uint32_t ui32Status; // // Get the interrrupt status. // ui32Status = ROM_UARTIntStatus(UART3_BASE, true); // // Clear the asserted interrupts. // ROM_UARTIntClear(UART3_BASE, ui32Status); // // Loop while there are characters in the receive FIFO. // while(ROM_UARTCharsAvail(UART3_BASE)) { printf("%c ", ROM_UARTCharsAvail(UART3_BASE)); // // Read the next character from the UART and write it back to the UART. // ROM_UARTCharPutNonBlocking(UART3_BASE, ROM_UARTCharGetNonBlocking(UART3_BASE)); } } //***************************************************************************** // // Send a string to the UART. // //***************************************************************************** void UARTSend(const uint8_t *pui8Buffer, uint32_t ui32Count) { // // Loop while there are more characters to send. // while(ui32Count--) { // // Write the next character to the UART. // ROM_UARTCharPutNonBlocking(UART3_BASE, *pui8Buffer++); } } //***************************************************************************** // // This example demonstrates how to send a string of data to the UART. // //***************************************************************************** int main(void) { tRectangle sRect; tContext sContext; // // Enable lazy stacking for interrupt handlers. This allows floating-point // instructions to be used within interrupt handlers, but at the expense of // extra stack usage. // ROM_FPULazyStackingEnable(); // // Set the clocking to run directly from the crystal. // ROM_SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); // // Initialize the display driver. // CFAL96x64x16Init(); // // Initialize the graphics context. // GrContextInit(&sContext, &g_sCFAL96x64x16); // // Fill the top part of the screen with blue to create the banner. // sRect.i16XMin = 0; sRect.i16YMin = 0; sRect.i16XMax = GrContextDpyWidthGet(&sContext) - 1; sRect.i16YMax = 9; GrContextForegroundSet(&sContext, ClrDarkBlue); GrRectFill(&sContext, &sRect); // // Change foreground for white text. // GrContextForegroundSet(&sContext, ClrWhite); // // Put the application name in the middle of the banner. // GrContextFontSet(&sContext, g_psFontFixed6x8); GrStringDrawCentered(&sContext, "uart-echo", -1, GrContextDpyWidthGet(&sContext) / 2, 4, 0); // // Initialize the display and write some instructions. // GrStringDrawCentered(&sContext, "Connect a", -1, GrContextDpyWidthGet(&sContext) / 2, 20, false); GrStringDrawCentered(&sContext, "terminal", -1, GrContextDpyWidthGet(&sContext) / 2, 30, false); GrStringDrawCentered(&sContext, "to UART3.", -1, GrContextDpyWidthGet(&sContext) / 2, 40, false); GrStringDrawCentered(&sContext, "115000,N,8,1", -1, GrContextDpyWidthGet(&sContext) / 2, 50, false); // // Enable the peripherals used by this example. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART3); // // Enable processor interrupts. // ROM_IntMasterEnable(); // // Set GPIO A0 and A1 as UART pins. // ROM_GPIOPinTypeUART(GPIO_PORTC_BASE, GPIO_PIN_7 | GPIO_PIN_6); // // Configure the UART for 115,200, 8-N-1 operation. // ROM_UARTConfigSetExpClk(UART3_BASE, ROM_SysCtlClockGet(), 115200, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE)); // // Enable the UART interrupt. // ROM_IntEnable(INT_UART3); ROM_UARTIntEnable(UART3_BASE, UART_INT_RX | UART_INT_RT); // // Prompt for text to be entered. // UARTCharPut(UART3_BASE, 49); // // Loop forever echoing data through the UART. // while(1) { UARTCharPut(UART3_BASE, 49); } }
Thank you.
Simple minded question here - does your PC actually have a (real) RS-232 style port?
Few do - these days - and as you detailed your use of a proper RS-232 level converter - you'd need a (real) RS-232 port @ your PC end.
You report success w/the original PC connection - that via USB. Most all PC's today support only USB - serial and parallel ports having long vanished.
Undescribed is "how" your PC will handle (real) RS-232 signal levels.... And - "looked at" is less comforting than "scoped" input & output of RS-232 level shifter...
Devil lives in (and loves) such details - all missing herein...
Shay Geva said:My PC does have a real RS-232 port
Good that - but due to the "rarity" of such (our firm special orders PCs w/serial ports) we had to ask. And - great "lightening" response by you!
Now may we move beyond "looked at?" Scope really simplifies/speeds data tracking between MCU's UART & level shifter's in/out.
Always there's the chance that your PC-side serial port requires HW "Handshake" - have you checked on that - and if possible - disabled it?
Eased way to test UART/RS-232 level shifter is via continuous transmission of 0x55 or 0xAA. (both produce equal width, alternating bit pattern)
First time wiring or cable (you may have a "null modem" cable or "straight-through" cable) - only one will work. (unless you modify) Depends upon your PC serial and your wiring at/to the level shifter.
BTW ... English is screwy language - your title broadcast "throw" (throw a ball) - "through" (means through a pipe)
We've moved a bit too fast for my tastes - and have avoided KISS. (that's our standard "modus operandi.")
As I understand your situation - you have a stand-alone PC which includes an RS232 port. And you have another maker's "driver."
We know nothing about this "driver."
May we establish the fact that you can exchange simple, ASCII readable text (0x20-0x7F) between your MCU and your PC? (eliminate the "driver" for now) It's vital that we proceed in small stages - too much - bundled together - always masks, lengthens and unduly complicates.
Please eliminate "strings" for now. Suggest that you attempt single (readable) character transmissions - between both your MCU and PC and PC and MCU. Use 0x41 "A" for example - so it's arrival @ PC will not be clouded.
Your sending a known (good) character (such as 0x41) and your report of results (after doing just that) speeds/simplifies diagnosis.
Continued use of "throw" rather than (corrected) "through" in your subject/title flags concern for your attention to detail...
OK,
The driver that i'm talking about is a Technosoft driver, but as you said i'm not using it for now, just tring to send 0x41 from the MCU to the PC.
So i still got nothing here, the MCU doesn't send data to the PC.
i attached the code that i'm downloading to the MCU if you want to review it.
//***************************************************************************** // // uart_echo.c - Example for reading data from and writing data to the UART in // an interrupt driven fashion. // // Copyright (c) 2011-2013 Texas Instruments Incorporated. All rights reserved. // Software License Agreement // // Texas Instruments (TI) is supplying this software for use solely and // exclusively on TI's microcontroller products. The software is owned by // TI and/or its suppliers, and is protected under applicable copyright // laws. You may not combine this software with "viral" open-source // software in order to form a larger program. // // THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL FAULTS. // NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT // NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. TI SHALL NOT, UNDER ANY // CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL // DAMAGES, FOR ANY REASON WHATSOEVER. // // This is part of revision 2.0.1.11577 of the DK-TM4C123G Firmware Package. // //***************************************************************************** #include <stdint.h> #include <stdbool.h> #include <stdio.h> #include "inc/hw_ints.h" #include "inc/hw_memmap.h" #include "driverlib/debug.h" #include "driverlib/fpu.h" #include "driverlib/gpio.h" #include "driverlib/interrupt.h" #include "driverlib/sysctl.h" #include "driverlib/uart.h" #include "driverlib/rom.h" #include "grlib/grlib.h" #include "drivers/cfal96x64x16.h" //***************************************************************************** // //! \addtogroup example_list //! <h1>UART Echo (uart_echo)</h1> //! //! This example application utilizes the UART to echo text. The first UART //! (connected to the USB debug virtual serial port on the evaluation board) //! will be configured in 115,200 baud, 8-n-1 mode. All characters received on //! the UART are transmitted back to the UART. // //***************************************************************************** //***************************************************************************** // // The error routine that is called if the driver library encounters an error. // //***************************************************************************** #ifdef DEBUG void __error__(char *pcFilename, uint32_t ui32Line) { } #endif //***************************************************************************** // // The UART interrupt handler. // //***************************************************************************** void UARTIntHandler(void) { uint32_t ui32Status; // // Get the interrrupt status. // ui32Status = ROM_UARTIntStatus(UART3_BASE, true); // // Clear the asserted interrupts. // ROM_UARTIntClear(UART3_BASE, ui32Status); // // Loop while there are characters in the receive FIFO. // while(ROM_UARTCharsAvail(UART3_BASE)) { printf("%c ", ROM_UARTCharsAvail(UART3_BASE)); // // Read the next character from the UART and write it back to the UART. // ROM_UARTCharPutNonBlocking(UART3_BASE, ROM_UARTCharGetNonBlocking(UART3_BASE)); } } //***************************************************************************** // // Send a string to the UART. // //***************************************************************************** void UARTSend(const uint8_t *pui8Buffer, uint32_t ui32Count) { // // Loop while there are more characters to send. // while(ui32Count--) { // // Write the next character to the UART. // ROM_UARTCharPutNonBlocking(UART3_BASE, *pui8Buffer++); } } //***************************************************************************** // // This example demonstrates how to send a string of data to the UART. // //***************************************************************************** int main(void) { tRectangle sRect; tContext sContext; // // Enable lazy stacking for interrupt handlers. This allows floating-point // instructions to be used within interrupt handlers, but at the expense of // extra stack usage. // ROM_FPULazyStackingEnable(); // // Set the clocking to run directly from the crystal. // ROM_SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); // // Initialize the display driver. // CFAL96x64x16Init(); // // Initialize the graphics context. // GrContextInit(&sContext, &g_sCFAL96x64x16); // // Fill the top part of the screen with blue to create the banner. // sRect.i16XMin = 0; sRect.i16YMin = 0; sRect.i16XMax = GrContextDpyWidthGet(&sContext) - 1; sRect.i16YMax = 9; GrContextForegroundSet(&sContext, ClrDarkBlue); GrRectFill(&sContext, &sRect); // // Change foreground for white text. // GrContextForegroundSet(&sContext, ClrWhite); // // Put the application name in the middle of the banner. // GrContextFontSet(&sContext, g_psFontFixed6x8); GrStringDrawCentered(&sContext, "uart-echo", -1, GrContextDpyWidthGet(&sContext) / 2, 4, 0); // // Initialize the display and write some instructions. // GrStringDrawCentered(&sContext, "Connect a", -1, GrContextDpyWidthGet(&sContext) / 2, 20, false); GrStringDrawCentered(&sContext, "terminal", -1, GrContextDpyWidthGet(&sContext) / 2, 30, false); GrStringDrawCentered(&sContext, "to UART3.", -1, GrContextDpyWidthGet(&sContext) / 2, 40, false); GrStringDrawCentered(&sContext, "115000,N,8,1", -1, GrContextDpyWidthGet(&sContext) / 2, 50, false); // // Enable the peripherals used by this example. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART3); // // Enable processor interrupts. // ROM_IntMasterEnable(); // // Set GPIO A0 and A1 as UART pins. // ROM_GPIOPinTypeUART(GPIO_PORTC_BASE, GPIO_PIN_7 | GPIO_PIN_6); // // Configure the UART for 115,200, 8-N-1 operation. // ROM_UARTConfigSetExpClk(UART3_BASE, ROM_SysCtlClockGet(), 115200, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE)); // // Enable the UART interrupt. // ROM_IntEnable(INT_UART3); ROM_UARTIntEnable(UART3_BASE, UART_INT_RX | UART_INT_RT); // // Prompt for text to be entered. // UARTCharPut(UART3_BASE, 0x41); // // Loop forever echoing data through the UART. // while(1) { UARTCharPut(UART3_BASE, 0x41); } }
Also i have another Q,
In the example code there is a function that handels the incomming data (UARTIntHandler). How can i view the data that this function get (for example if i want to print it to the console using printf)?
Thanks
Shay Geva said:i [sic] I still got nothing here, the MCU doesn't send data to the PC.
How do you know that?
1) Have you checked w/scope to observe bit patterns flow from MCU's UART_TX to TX_IN of RS232 level shifter? And then
2) If "1" appears "normal" - have you then moved your scope to TX_OUT (i.e. RS232 levels now) and observed the data input to TX_IN now "INVERTED" and significantly level shifted (when you monitor TX_OUT?
3) Earlier I provided "alternating bit" codes to speed/ease such test. Your level shifter raises the voltages and inverts the signals introduced upon it's TX_IN pin. Minus your report of success at the "level shifter" - all else reduces to, "guesswork." (not really my/other's interest)
Should the level shifter scope monitoring "pass" (as described here) check and double check your cable and or connections to the PC. Are you quite certain that all connections are proper? Have you any means to (independently) test your PC's serial port?
I cannot recall what program you are using @ PC side for serial terminal. Many of these (default) into HW handshake - which you must disable! (as I past noted) your job is to insure that HW handshake is disabled - or we (continue) to spin our wheels.
You may edit your first post's subject to replace "throw" with the word you intended, "through." Or you may replace "throw" with "via."
Feel you pain - detail instructions past provided have (always) led to serial port "fix."
Thank you for correcting your subject - new forum "blows up" each title - to have an error there is disturbing.
If your scope shows no data movement from UART_TX - you're stuck. If that's (really) the case - I fear you may have connected (at some point) the RS-232 level shifter's RS232 levels to the MCU - which (often) proves destructive.
Are you sure that your scope is working? Have you measured 3V3 on your board - and then the HV (~12VDC) upon your RS232 level shifter - prior to measuring UART_TX @ the MCU? Are you sure that you're probing the correct pin(s).
One guy - even looking over connections - may not prove best. Even a hand drawn schematic - posted here - gains you "many" eyes for review. (often I "cannot see" my own (repeated) mistake - that's why Lone Ranger so often fails - where small team succeeds.)
Suggest that you switch that UART_TX pin on your MCU to GPIO Output - and pulse it. Then monitor w/your scope. If pin is "dead" you'll soon know it. But if it works as GPIO - suspect it will work as UART - too.
We need small, careful steps now. Frustration helps no one - you've got your direction - I fly in an hour so farewell...