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.
This my uart code. When i change uart1 interrupt, it doesn't work. but uart0 wroks. Where is my mistake?
Thanks
#include <stdint.h> #include <stdbool.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/pin_map.h" #include "driverlib/rom.h" #include "driverlib/sysctl.h" #include "driverlib/uart.h" #include "utils/uartstdio.h" void ConfigureUART0(void) { ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0); ROM_GPIOPinConfigure(GPIO_PA0_U0RX); ROM_GPIOPinConfigure(GPIO_PA1_U0TX); ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1); UARTClockSourceSet(UART0_BASE, UART_CLOCK_PIOSC); UARTStdioConfig(0, 115200, 16000000); } void ConfigureUART1(void) { SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); SysCtlPeripheralEnable(SYSCTL_PERIPH_UART1); GPIOPinConfigure(GPIO_PB0_U1RX); GPIOPinConfigure(GPIO_PB1_U1TX); GPIOPinTypeUART(GPIO_PORTB_BASE, GPIO_PIN_0 | GPIO_PIN_1); UARTClockSourceSet(UART1_BASE, UART_CLOCK_PIOSC); UARTConfigSetExpClk(UART1_BASE, 16000000, 115200, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE)); UARTEnable(UART1_BASE); } //***************************************************************************** // // The UART interrupt handler. // //***************************************************************************** void UARTIntHandler(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)); } GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, GPIO_PIN_2); SysCtlDelay(SysCtlClockGet() / (1000 * 3)); GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, 0); } //***************************************************************************** // // Send a string to the UART. // //***************************************************************************** void UART0Send(const uint8_t *pui8Buffer, uint32_t ui32Count) { while(ui32Count--) { ROM_UARTCharPutNonBlocking(UART0_BASE, *pui8Buffer++); } } void UART1Send(const uint8_t *pui8Buffer, uint32_t ui32Count) { while(ui32Count--) { ROM_UARTCharPutNonBlocking(UART1_BASE, *pui8Buffer++); } } //***************************************************************************** // // This example demonstrates how to send a string of data to the UART. // //***************************************************************************** int main(void) { ROM_FPUEnable(); ROM_FPULazyStackingEnable(); ROM_SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |SYSCTL_XTAL_16MHZ); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); // Enable the GPIO pins for the LED (PF2). ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_2); ConfigureUART0(); ConfigureUART1(); ROM_IntMasterEnable(); ROM_IntEnable(INT_UART1); ROM_UARTIntEnable(UART1_BASE, UART_INT_RX | UART_INT_RT); // Prompt for text to be entered. UART0Send((uint8_t *)"\033[2JEnter text: ", 16); UART1Send((uint8_t *)"UART1\n\r", 7); // UART2Send((uint8_t *)"UART2\n\r", 7); while(1) { } }
Are you aware that only "UART_0" is "brought out" from the '123 LPad via the ICDI MCU? (Converts the MCU's UART CMOS signal levels to USB compatible ones.)
UART_1 (and all others) are absent that "signal level conversion" - and this (likely) explains your report of, "Doesn't Work." Unless you "hack your board" - you cannot "exploit" the ICDI MCU - to manage the (required) UART_1 <-> USB communication channel.
"Doesn't Work" fails to adequately describe, "What, Where & How" you fail - all such facts useful to your assistance... As one example - we've no idea what type of device you are targeting for UART Communication. You can communicate between another "UART-type" device - so long as the signal levels between each are proper - and the cable length is short. (meter or less)
The "usual suspect" for such "UART-Terminal type" communication is a "PC" - and modern ones speak ONLY USB - which demand a "UART/CMOS level to USB Converter" - to enable such communication...
thanks for reply . I think i forgot to write. I use TTL converter. so when i use uart1, i connect pc to board via TTL converter. already i saw serial message at serial port monitor. But interrupt doesn't work
Indeed that "Converter Use" was missed - and as that is the "usual cause" I simply glanced @ your interrupt handler. Middle of the night here (US midwest) - I'll be back to you when (fully) conscious ... (later).
Sleep proves "over-rated" - here's my "best guess" as to what you need to succeed...
Our preference is to avoid "registering" such interrupts (far too complex & error prone) - instead enter them w/in the "Start-Up file" - here's my detailed example:
Have you modified your "Start-Up file" to "change" UART1's "default handler" to your, "UARTIntHandler?" Assuming that you succeeded w/UART0 - and interrupted successfully there - you must have replaced UART0's "default handler" with "UARTIntHandler" - is that not true? BTW - I believe that your handler name is "too vague" - adding the UART being targeted (UART1) makes more sense - does it not?
You must make TWO unique entries w/in the start-up file: one w/in "External Declarations" (shown) and one w/in "Vector Table" (also shown).
Note the use of bold and color - to "drive home" the assignment of each interrupt...
//*****************************************************************************
//
// External declarations for the interrupt handlers used by the application.
//
//*****************************************************************************
extern void IntDefaultHandler(void);
extern void ADC0IntHandler(void); // Normal pgm opn.
extern void ADC0SS0Handler(void); // ADC Sanity/Connection tests
extern void GPIOBIntHandler(void); // Hall-Sense
extern void CANIntHandler(void);
extern void FaultISR(void);
extern void NmiSR(void);
extern void PWM0IntHandler(void); // PWM Generator
extern void QEIIntHandler(void);
extern void SysTickIntHandler(void); // Switch, Spd Pot
extern void WTimer0AIntHandler(void); // Integ. Sat (4 Sec)
extern void WTimer2BIntHandler(void); // Stall Detect (2 Sec)
extern void Timer1BIntHandler(void); // TAK 500uS
extern void Timer3AIntHandler(void); // Program Time Base
extern void WatchdogIntHandler(void);
and then (below w/in the Start-Up file's "Vector Table")
WatchdogIntHandler, // Watchdog timer
IntDefaultHandler, // Timer 0 subtimer A
IntDefaultHandler, // Timer 0 subtimer B
IntDefaultHandler, // Timer 1 subtimer A
Timer1BIntHandler, // Timer 1 subtimer B
IntDefaultHandler, // Timer 2 subtimer A
IntDefaultHandler, // Timer 2 subtimer B
IntDefaultHandler, // GPIO Port H
IntDefaultHandler, // UART2 Rx and Tx
IntDefaultHandler, // SSI1 Rx and Tx
Timer3AIntHandler, // Timer 3 subtimer A
IntDefaultHandler, // Timer 3 subtimer B
WTimer0AIntHandler, // Wide Timer 0 subtimer A
IntDefaultHandler, // Wide Timer 0 subtimer B
IntDefaultHandler, // Wide Timer 1 subtimer A
IntDefaultHandler, // Wide Timer 1 subtimer B
IntDefaultHandler, // Wide Timer 2 subtimer A
WTimer2BIntHandler, // Wide Timer 2 subtimer B
Thanks to you as well my friend. Again - strongly recommend against your "Registering Interrupts" - the method (illustrated, post above) "Embedding w/in the Start-Up file" proves faster, easier and less taxing upon SRAM resources - which should always be conserved...
Bon chance, mon ami...