--- Quote Start ---
Hi! May I know what do you receive on your HyperTerminal? I keep receiving a 7 look alike thing at hyperterminal and when I copy and paste it in here , it become a ª.
How may I solve it?
And at the Nios II Console, Random number are coming out.
Example I type in...
3 and the result is 33
a and the result is 61
s and the result is 73
May I know where ran wrong? I am suppose to test by sending something to uart and read from it then display it on Nios II console.
Can anyone tell me what does the 0xFF,0xAA, count/256 and count%256 are for?
Sorry for all these questions...
--- Quote End ---
Surely in the meanwhile you have found the answers but if not:
"
example i type in...
3 and the result is 33
a and the result is 61.."
these are the exadecimal ascii codes of the keys you are pressing, simply search for ASCII Table and you can know why.
"
can anyone tell me what does the 0xff,0xaa, count/256 and count%256 are for?"
I think
naceradsky added it only for testing purpose, just to show what is happening!
UART rs232 used as stdio:
Regarding other "very old" questions posted in the forum related to programs that have to continue "working" without waiting for user inputs (i.e.:keystroke via UART terminal) I have found my own little solution.
I'm not a software developer and I'm not able to use "high level" functions, but I noticed that when tyr to use functions that involve stdin & stdout like "printf" or "scanf" this functions (obviously) accesses and alter the UART registers. So if we want to access UART using those registers we don't have to use stdio functions.
I have first tryed using o_nonblock (niosII 9.1 sp2) but for me it doesn't work well, so I wrote an horrible code probably, but for my tests is working fine, this is an extraction from my altered version of Altara's "board_diag", i'll post it if any beginner would like to take a look!
! This is not a full code!
*
* static void TestSW_INPUT(void)
*
* function that reads swithces status on DE1 board
* write switches value on red led and have a free running counter 1 to F
* and display count on green led and on terminal rs232
* It exits when the user types a 'q'.
*/
static void TestSW_INPUT(void)
{
alt_u16 sw_input;
alt_u16 count = 0x0000;
char char_count[81];
int num_char_count;
char stop ='0';// ...can also use a boolean flag ...
//static char entry[4];//used for previous tests
alt_u16 UartSts;
alt_u16 CntrOrig;
alt_u16 rrdy = 0x0000;
alt_u16 tmt = 0x0000;//transmitter empty
//fcntl(STDIN_FILENO, F_SETFL, O_NONBLOCK);//sets uart in non blocking mode
printf( "\r\n press 'q' to EXIT \n\r");
printf( "\r\n or change switches to show their value \n\r");
//usleep(10000);
CntrOrig=IORD_ALTERA_AVALON_UART_CONTROL(UART_BASE);//save original uart control reg
while (count < 0x0f && stop != 'q' )
{
/*while (tmt != 0x0020)//wait for any tx
{
UartSts = IORD_ALTERA_AVALON_UART_STATUS(UART_BASE);//read UART status reg
tmt = UartSts & 0x0020;//test tmt
}*/ //previous tests!!
IOWR_ALTERA_AVALON_UART_CONTROL(UART_BASE,0x00);//erase masks if any!
/* Read HW switches status */
sw_input = IORD_ALTERA_AVALON_PIO_DATA(SW_INPUT_BASE);
IOWR_ALTERA_AVALON_PIO_DATA(LED_R_BASE, sw_input);
IOWR_ALTERA_AVALON_PIO_DATA(LED_PIO_BASE, count);
//usleep(1000000);
UartSts = IORD_ALTERA_AVALON_UART_STATUS(UART_BASE);//read UART status reg
rrdy = UartSts & 0x0080;//test RRDY
if (rrdy == 0x80)
{
stop=IORD_ALTERA_AVALON_UART_RXDATA(UART_BASE);
}
count++;
usleep(100000);//delay to avaluate funcionality
num_char_count = sprintf(char_count, "count value is: %x \n",count);
for (int i=0; i<=num_char_count;i++)
{
IOWR_ALTERA_AVALON_UART_TXDATA(UART_BASE,char_count[i]);
usleep(1000);
}
IOWR_ALTERA_AVALON_UART_TXDATA(UART_BASE,0x0D);//CR
}
//fcntl(STDIN_FILENO, F_SETFL, EWOULDBLOCK);////set back uart in blocking mode?
//sscanf( entry, "%c\n", &stop );//need to empty entry?
IOWR_ALTERA_AVALON_UART_CONTROL(UART_BASE,CntrOrig);//set back original uart_control value
printf(".....Exiting TestSW_INPUT.\n\r");
}
note that I have use STDIO function "printf" but outside the direct acces of UART functionality.