Quantcast
Channel: Altera Forums
Viewing all articles
Browse latest Browse all 19390

UART using NIOS II

$
0
0
Hi again,
I already posted a topic about nios ii altera ans esp8266, I fixed all my problems with the esp8266, now i still struggling with my uart C code, my transmit function works well, but with my receive function its always a mess, its sometimes only if I don't use it, I just tried to return from my receive function two values: the received message and its size, I tried the following code but it does not work at all:
Code:

void uart_write(char* comm)
{
 message* mess ;
 int count=0;
 strcpy(mess->send,comm);//command
 mess->lenS=strlen(mess->send);//command length
 for (count=0;count<mess->lenS;count++)
 {
        if(ALTERA_AVALON_UART_STATUS_TRDY_MSK==TRDY)// check if transmit ready
        {
                IOWR_ALTERA_AVALON_UART_TXDATA(UART_BASE,mess->send[count]);//send character
                Delay(600);//wait the end of transmission
        }
 }
 if (ALTERA_AVALON_UART_STATUS_TRDY_MSK == TRDY)// check if transmit ready
        IOWR_ALTERA_AVALON_UART_TXDATA(UART_BASE,0X0D);//        \r
 if (ALTERA_AVALON_UART_STATUS_TRDY_MSK == TRDY)// check if transmit ready
        IOWR_ALTERA_AVALON_UART_TXDATA(UART_BASE,0x0A);//        \n
}
void receive(char *buffer, int size){
        alt_u8 status;
        status= IORD_ALTERA_AVALON_UART_STATUS(UART_BASE);
        while((status & RRDY)==RRDY        ){        // check if reception ready{
                buffer[size]=IORD_ALTERA_AVALON_UART_RXDATA(UART_BASE);//receive character
                status= IORD_ALTERA_AVALON_UART_STATUS(UART_BASE);                        //update status register
                size++;
                }
}
int main()
{
uart_init();
int size=0;
char *buffer;
uart_write("AT+CWLAP");
receive(&buffer,size);
printf("%d \n %s",size,buffer);
return 0; }

please guys I need help I'm lost
Thanks a lot

Viewing all articles
Browse latest Browse all 19390

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>