File tree Expand file tree Collapse file tree 1 file changed +10
-9
lines changed Expand file tree Collapse file tree 1 file changed +10
-9
lines changed Original file line number Diff line number Diff line change 2323#define F_CPU 3333333
2424#define USART1_BAUD_RATE (BAUD_RATE ) ((float)(F_CPU * 64 / (16 * (float)BAUD_RATE)) + 0.5)
2525#define MAX_COMMAND_LEN 8
26- #define INIT_DELAY 10 /* delay in ms */
26+ #define INIT_DELAY 10 /* Delay to invalidate the after-reset noise on the PC0 pin (TX) */
2727
2828#include <avr/io.h>
2929#include <stdio.h>
@@ -41,12 +41,12 @@ void executeCommand(char *command);
4141
4242void USART1_init (void )
4343{
44- PORTC .DIR &= ~PIN1_bm ;
45- PORTC .DIR |= PIN0_bm ;
46-
4744 USART1 .BAUD = (uint16_t )USART1_BAUD_RATE (9600 );
4845
4946 USART1 .CTRLB |= USART_RXEN_bm | USART_TXEN_bm ;
47+
48+ PORTC .DIR |= PIN0_bm ;
49+ PORTC .DIR &= ~PIN1_bm ;
5050}
5151
5252void USART1_sendChar (char c )
@@ -114,12 +114,13 @@ int main(void)
114114 char command [MAX_COMMAND_LEN ];
115115 uint8_t index = 0 ;
116116 char c ;
117-
118- LED_init ();
117+
118+ /* This delay invalidates the initial noise on the TX line, after device reset. */
119+ _delay_ms (10 );
120+
119121 USART1_init ();
120-
121- _delay_ms (INIT_DELAY );
122-
122+ LED_init ();
123+
123124 USART1_sendString ("Type ON/OFF to control the LED.\r\n" );
124125
125126 while (1 )
You can’t perform that action at this time.
0 commit comments