We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hi , I am looking for the code for uart0 for STR9 in which wnen ever I send some character form the terminal it should just jump to the interrupt handler print taht character then come back can any one please help it should be like this
#include "91x_lib.h" #include "stdio.h" #include <91x_lib.h> #include <string.h> #include <limits.h> u16 LedPulse = 0,tmp = 0; GPIO_InitTypeDef GPIO_InitStructure; static unsigned int tx_restart = 1; /* NZ if TX restart is required */ void UART0_IRQHandler(void); void com_baudrate (unsigned int baudrate) { unsigned long BRDi = 0, BRDf = 0; unsigned long long UARTClk = 48000000; if ((SCU->CLKCNTR & SCU_BRCLK_Div2) != SCU_BRCLK_Div2) { UARTClk /= 2; /* set UART Clock acc. BRSEL */ } /* baudrate calculation */ BRDi = ((100 * UARTClk) / (16 * baudrate)); /* calculate the integer part */ BRDf = BRDi - (100 * (BRDi / 100)); /* calculate the fractal part */ UART0->CR &= 0xFFFE; /* disable UART */ UART0->IBRD = BRDi / 100; /* set the integer part */ UART0->FBRD = ((((BRDf * 64) + 50) / 100)); /* set the fractal part */ UART0->LCR &= 0xFFFF; /* to accept baudrate */ UART0->CR |= 0x0001; /* enable UART */ } int SendChar (int ch) { UART_SendData(UART0, ch); while(UART_GetFlagStatus(UART0, UART_FLAG_Busy) != RESET); return (ch); } int GetKey (void) { while ((UART0->FR & 0x10)); /* RX Fifo Empty */ return (UART0->DR); } void com_initialize (void) { /*------------------------------------------------ Setup serial port registers. ------------------------------------------------*/ UART0->LCR = UART_WordLength_8D /* 8 bits */ | UART_Parity_No /* no Parity */ | UART_HardwareFlowControl_None /* no flow control */ & UART_StopBits_1 /* 1 Stop bit */ & UART_FIFO_Disable; /* FIFO disabled */ UART0->CR = UART_Mode_Rx /* Receive Enable */ | UART_Mode_Tx /* Transmit Enable */ | 0x0001; /* UART Enable */ // UART0->IMSC = UART_IT_Transmit /* Enable Tx Interrupt */ // |UART_IT_Receive ; /* Enable Rx Interrupt */ UART0->IMSC = UART_IT_Receive ; /* Enable Rx Interrupt */ com_baudrate (115200); /* 115200 */ /*------------------------------------------------ Setup Default Interrupt ------------------------------------------------*/ //VIC0->DVAR = (unsigned int)def_irq; //VIC1->DVAR = (unsigned int)def_irq; /*------------------------------------------------ Setup UART0 Interrupt, UART0_ITLine = 16 ------------------------------------------------*/ // VIC1->VAiR[3] = (unsigned int)UART0_IRQHandler; /* set IRQ handler */ // VIC1->INTSR &= ~(0x01 << (UART0_ITLine - 16)); /* generate an IRQ interrupt */ ///VIC1->VCiR[3] = 0x20 | (UART0_ITLine - 16); /* enable vetored interrupt No 0 */ //VIC1->INTER |= (0x01 << (UART0_ITLine - 16)); /* enable the interrupt */ SCU_AHBPeriphClockConfig(__VIC,ENABLE); SCU_AHBPeriphReset(__VIC,DISABLE); VIC_DeInit(); VIC_Config(UART0_ITLine, VIC_IRQ, 0); VIC_ITCmd(UART0_ITLine, ENABLE); } void LEDINIT() { GPIO_DeInit(GPIO9); GPIO_InitStructure.GPIO_Direction = GPIO_PinOutput; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1 ; GPIO_InitStructure.GPIO_Type = GPIO_Type_PushPull ; GPIO_Init (GPIO9, &GPIO_InitStructure); GPIO_WriteBit(GPIO9, GPIO_Pin_0, Bit_RESET); GPIO_WriteBit(GPIO9, GPIO_Pin_1, Bit_RESET); } void main(void) { SCU_APBPeriphClockConfig(__GPIO9, ENABLE); LEDINIT(); SCU->GPIOIN[5] = 0x0002; SCU->PCGR1 |=0x8; SCU->GPIOOUT[5] = 0x03; /* P5.1 input UART0 RX */ SCU_APBPeriphReset(__UART0,ENABLE); SCU_APBPeriphReset(__UART0,DISABLE); com_initialize(); GPIO_WriteBit(GPIO9, GPIO_Pin_0, Bit_SET); while(1) { if(tmp>0) {// Delay(0xFFF); // printf("."); //GPIO_WriteBit(GPIO9, GPIO_Pin_0, Bit_RESET); //GPIO_WriteBit(GPIO9, GPIO_Pin_1, Bit_RESET); //tmp=0; } //tmp=0; } //tmp=0; } void UART0_IRQHandler(void) { volatile unsigned int IIR; unsigned char ch; //tmp++; while ((IIR = UART0->MIS) & (UART_IT_Transmit | UART_IT_Receive)) { if (IIR & UART_IT_Receive) { UART0->ICR = UART_IT_Receive; /* clear the interrupt */ GPIO_WriteBit(GPIO9, GPIO_Pin_0, Bit_SET); printf("%c",ch); } } GPIO_WriteBit(GPIO9, GPIO_Pin_1, Bit_SET); VIC1->VAR = 0; /* Acknowledge Interrupt */ } </p> what happened in this code is that uart does not comes out from the handler what may be reason i am not able to get