HI everyone,
I have modified the UART0 echo code to use UART1..in order to communicate with uart1 through PC by making use of PD2 and PD3 pins as RX and TX pins
1.I am using a MAX232 level converter and connecting UART1 to PC through a DB9 connector
2. I have also changed the Interrupt Vector to UARTInthandler for Uart1 tx and rx
3. I am using the GPIOPin Configure also
4. HWREG is also used in order to assign the PD2 and PD3
#include "inc/hw_ints.h"#include "inc/hw_memmap.h"#include "inc/hw_types.h"#include "inc/hw_gpio.h"#include "driverlib/debug.h"#include "driverlib/gpio.h"#include "driverlib/interrupt.h"#include "driverlib/rom.h"#include "driverlib/sysctl.h"#include "driverlib/uart.h"//*****************************************************************************////! \addtogroup example_list//! <h1>UART (uart_echo)</h1>//!//! This example application utilizes the UART to echo text. The first UART//! (connected to the FTDI 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 DEBUGvoid__error__(char *pcFilename, unsigned long ulLine){}#endif//*****************************************************************************//// The UART interrupt handler.////*****************************************************************************voidUARTIntHandler(void){ unsigned long ulStatus; // // Get the interrrupt status. // ulStatus = ROM_UARTIntStatus(UART1_BASE, true); // // Clear the asserted interrupts. // ROM_UARTIntClear(UART1_BASE, ulStatus); // // Loop while there are characters in the receive FIFO. // while(ROM_UARTCharsAvail(UART1_BASE)) { // // Read the next character from the UART and write it back to the UART. // ROM_UARTCharPutNonBlocking(UART1_BASE, ROM_UARTCharGetNonBlocking(UART1_BASE)); }}//*****************************************************************************//// Send a string to the UART.////*****************************************************************************voidUARTSend(const unsigned char *pucBuffer, unsigned long ulCount){ // // Loop while there are more characters to send. // while(ulCount--) { // // Write the next character to the UART. // ROM_UARTCharPutNonBlocking(UART1_BASE, *pucBuffer++); }}//*****************************************************************************//// This example demonstrates how to send a string of data to the UART.////*****************************************************************************intmain(void){ // // Set the clocking to run directly from the crystal. // ROM_SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); HWREG(GPIO_PORTD_BASE + GPIO_O_PCTL) = (HWREG(GPIO_PORTD_BASE + GPIO_O_PCTL) & ~(GPIO_PCTL_PD2_M | GPIO_PCTL_PD3_M)) | (GPIO_PCTL_PD2_U1RX | GPIO_PCTL_PD3_U1TX); // // Enable the peripherals used by this example. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART1); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); // // Enable processor interrupts. // ROM_IntMasterEnable(); // // Set GPIO A0 and A1 as UART pins. // GPIOPinConfigure(GPIO_PD2_U1RX); GPIOPinConfigure(GPIO_PD3_U1TX); ROM_GPIOPinTypeUART(GPIO_PORTD_BASE, GPIO_PIN_2 | GPIO_PIN_3); // // Configure the UART for 115,200, 8-N-1 operation. // ROM_UARTConfigSetExpClk(UART1_BASE, ROM_SysCtlClockGet(), 115200, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE)); // // Enable the UART interrupt. // ROM_IntEnable(INT_UART1); ROM_UARTIntEnable(UART1_BASE, UART_INT_RX | UART_INT_RT); // // Prompt for text to be entered. // UARTSend((unsigned char *)"\033[2JEnter text: ", 16); // // Loop forever echoing data through the UART. // while(1) { }}
Can anyone Please check and tel me.. wat am i missing am able to get echo back for UART0 but not for UART1.. am totally frustrated have been trying alot and am desperate
for a solution Pls Help me!!!
Did you try running this with a debugger?
If you had, you would have seen that your code was faulting almost immediately.
You access peripheral registers before you enable the peripheral.
Hi Slandrum,
Thank you for pointing that out to me.. I have modified the code by placing this
HWREG(GPIO_PORTD_BASE + GPIO_O_PCTL) = (HWREG(GPIO_PORTD_BASE + GPIO_O_PCTL) & ~(GPIO_PCTL_PD2_M | GPIO_PCTL_PD3_M)) | (GPIO_PCTL_PD2_U1RX | GPIO_PCTL_PD3_U1TX);
below this
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART1); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
But still there's no change ...
Since I am a newbie to this IAR debugger which I am using.. I am still not understanding the fault....
Can you please explain where I am going wrong.. I really need to understand this..
Since you are using interrupts for the UART, have you modified the interrupt vector table so that the UART1 vector points to your interrupt handler?
The interrupt vector table should be in a startup file, probably called something like startup_xxx.c where xxx is the name of the toolchain you are using.
EDIT: Never mind, I now see that in your first post you say that you have done this.
I don't use IAR, so someone else will have to help you with anything that's specific to IAR. Normally for debugging something like this, it's useful to step through your code one function call at a time and see where it ends up in the fault handler.
Another thing I notice:
Why are you calling the non-blocking version of UARTCharPut() in your UARTSend() function? This is guaranteed to not do what you want when you try to send too many characters at a time, as the hardware FIFO will fill up, then you'll just drop the rest of the characters without sending them. The non-blocking version of a function always returns immediately whether or not it can perform the desired operation, and you must check its return value to see whether or not it succeeded, unless you know in advance that it must succeed (for instance you know that there's room in the Tx FIFO for the next character), or you really don't care whether the call works or not.
In general, you do not want to call the non-blocking versions of the functions when you really want the data to go out. If you can do something else when the hardware is busy, for instance yield to other tasks, you can call the non-blocking version, check the result, and if it failed do a task yield then loop back and try again.
I have actually modified the uart_echo example provided by the stellarisware examples... For UART0 to UART1 ...
That is why the non blocking function has been called...
I am still not clear as to where the problem is.. whether hardware or software..
can u please tell me.. if my hardware connections are correct ?
1.I have used a max232 level converter chip to connect the PD2 and PD3 pins of the GPIO port D for TXD and RXD
2. the ground pins are also connected to the RS232 DB9 connector..
Is there anythingelse am missing in the hardware side..
am making use of a usb to serial converter to communicate with the UART1 and my Laptop..from COM1 which uses the ProlificUSB toSerial
and the stellaris board uses COM9 both are configured to a Baud rate of 115200.
Any help will be appreciated...