Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++

uart help?

Altera_Forum
Honored Contributor II
1,241 Views

hardware:apex20K200E 

software:quartus+sp1+nios 

I want to receive the message access the uart .The information is attained by Simense GSM module.Please correct the code as follows: 

 

// 

//#include "buffer.h" // defines RXBUFSIZE and TXBUFSIZE# include <stdio.h># include "excalibur.h"# include "nios.h" 

# define RXBUFSIZE 256 

//#define TXBUFSIZE 256 

 

//Global variables 

unsigned char RxBuf[RXBUFSIZE]; // the receiver buffer. 

int RxHead = 0; // the circular buffer index 

int RxTail = 0; 

//unsigned char TxBuf[TXBUFSIZE]; // the transmit buffer. 

//int TxHead = 0; // the circular buffer index 

//int TxTail = 0; 

 

void simpleReceiver1(int context); 

unsigned char _getchar(); 

void MyPIO_ISR(int context); 

 

int main(void) 

int context = 0; 

int bidir_port_to_and_from_the_led_pio[1]; 

unsigned char rxchar; 

np_pio *pio = na_led_pio; 

 

nr_installuserisr(na_uart1_irq, simpleReceiver1, context); // install UART ISR (receiver) 

na_uart1->np_uartcontrol = np_uartcontrol_irrdy_mask; // enable rrdy interrupt 

 

while(1) 

rxchar = _getchar(); 

printf("\nfrom RxBuf: %c \n",rxchar); 

 

 

nr_installuserisr(na_button_pio_irq,MyPIO_ISR,(int)pio); 

 

pio->np_pioedgecapture = 0; // clear any existing IRQ condition 

pio->np_piodirection = 0; // all input 

pio->np_piointerruptmask = 0xff; // they all generate irq&#39;s! 

 

// bidir_port_to_and_from_the_led_pio[1]=1; 

 

return 0; 

 

 

// pass an int to make it compatible with nr_installuserisr2 routine 

// contents of third argument ("context") in nr_installuserisr is passed to ISR 

void simpleReceiver1(int data) 

// put new char into buffer from UART 

RxBuf[RxHead] = na_uart1->np_uartrxdata;  

// clear the errors and interrupts 

na_uart1->np_uartstatus=0;  

 

if ((++RxHead) > (RXBUFSIZE-1))  

RxHead = 0; 

 

//receive _getchar 

unsigned char _getchar() 

//Global variables 

//unsigned char RxBuf[RXBUFSIZE]; // the receiver buffer. 

//int RxHead; // the circular buffer index 

//int RxTail; 

unsigned char temp; 

 

while (RxTail == RxHead) 

nr_delay(1); 

temp = RxBuf[RxTail]; 

 

if (++RxTail > (RXBUFSIZE -1)) 

RxTail = 0; 

return(temp); 

void MyPIO_ISR(int context) 

int bidir_port_to_and_from_the_led_pio[1]; 

np_pio *pio = (np_pio *)context; 

char s[256]; // a string 

 

pio->np_pioedgecapture = 0; // clear the irq condition 

 

bidir_port_to_and_from_the_led_pio[1]=1; 

}
0 Kudos
0 Replies
Reply