AW: [En-Nut-Discussion] scanf on uart0: Reboot - loop
Oliver Schulz
olischulz at web.de
Sun Dec 19 14:30:42 CET 2004
Hi Ernst,
The devDebug0 device is for output only. It doesn't support reading
characters from the serial interface.
To do this, use the devUsartAvr0 device.
Regards,
Oliver.
-----Ursprüngliche Nachricht-----
Von: en-nut-discussion-bounces at egnite.de
[mailto:en-nut-discussion-bounces at egnite.de] Im Auftrag von Ernst Stippl
Gesendet: Sonntag, 19. Dezember 2004 11:59
An: 'Ethernut User Chat (English)'
Betreff: [En-Nut-Discussion] scanf on uart0: Reboot - loop
Hi!
I am trying to read from the serial i/f which is connected to a terminal emu
using scanf. In most circumstances, the program loops i.e. when hitting the
scanf, the main function starts from the beginning.
I tried to minimize th eprogram and sometimes the problem disappears but
when adding statements again, the reboot loop appears again.
I am using an 2.1b board and Nut/OS 3.9.1
Here is a sample program which produces the problem:
//-----------------------------------------------------------------------
int main(void)
{
u_long baud = 115200;
u_char mac[6] = { 0x00, 0x06, 0x98, 0x21, 0x03, 0xC8 }; u_long ip_addr;
u_long ip_mask; u_long i_adr; u_char addr_string[16] = "192.168.171.199";
u_short i;
addr_string[15] = 0;
/*
* Register all devices used in our application.
*/
NutRegisterDevice(&devDebug0, 0, 0);
NutRegisterDevice(&DEV_ETHER, 0x8300, 5);
/*
* Assign stdout/in to the UART device.
*/
freopen("uart0", "w", stdout);
freopen("uart0", "r", stdin);
_ioctl(_fileno(stdout), UART_SETSPEED, &baud); _ioctl(_fileno(stdin ),
UART_SETSPEED, &baud);
//NutRegisterDevice(&devUart0, 0, 0);
//uart = fopen("uart0", "r+");
//_ioctl(_fileno(uart), UART_SETSPEED, &baud);
printf ("\nBooting\n");
NutNetLoadConfig("eth0");
ip_addr = inet_addr("192.168.171.5");
ip_mask = inet_addr("255.255.255.0");
NutNetIfConfig("eth0", mac, ip_addr, ip_mask);
puts ("config OK, now arping");
printf ("IP: %s\n", inet_ntoa(confnet.cdn_ip_addr));
printf ("Enter IP Adr to be PINGed: "); // if these lines are executed
scanf ("%s", addr_string); // the printf-string appears on the
term
for (i = 0; i < 17; i++) // and immediately, the board
restarts.
if (addr_string [i] == (u_char) 13) //
addr_string[i] = (u_char) 0; //
i_adr = inet_addr (addr_string);
do_work (i_adr);
printf ("\nWork ended\n");
while (1)
NutSleep ((u_long) 2000);
}
_______________________________________________
En-Nut-Discussion mailing list
En-Nut-Discussion at egnite.de
http://www.egnite.de/mailman/listinfo.cgi/en-nut-discussion
More information about the En-Nut-Discussion
mailing list