Todo:
- Update main.c to disable the
digital input buffer on all I/O pins.
- Update driver_isr.c to configure
the USART TX pin as output pin during data transmission and as input pin during no data
transmission period.
- 1.Edit the main.c file:
- 1.1.Disable the digital input buffer on all
I/O pins by adding in the following function before the
main()
function.
//Disable digital input buffer on all IO pins
void io_init(void)
{
for (uint8_t pin=0; pin < 8; pin++)
{
(&PORTA.PIN0CTRL)[pin] = PORT_ISC_INPUT_DISABLE_gc; //Disable on PAx pin
(&PORTB.PIN0CTRL)[pin] = PORT_ISC_INPUT_DISABLE_gc; //Disable on PBx pin
(&PORTC.PIN0CTRL)[pin] = PORT_ISC_INPUT_DISABLE_gc; //Disable on PCx pin
}
}
Info: PORT_ISC_INPUT_DISABLE_gc will set the digital input buffer disabled. Hover
over it and right-click ->Goto Implementation will open the iotn817.h
file and point to where it is defined.
- 1.2.Call the function by adding the
following code after the atmel_start_init(); line in main() function.
//Disable digital input buffer on all IO pins
io_init();
- 2.Edit the driver_isr.c file:
- 2.1.Add the following line of code at the
start of the
ISR(ADC0_RESRDY_vect)
function:VPORTB.DIR |= PIN2_bm; //Configure USART TX pin PB2 as output pin
- 2.2.Add the following line of code after
the USART transmission is completed in the
ISR(ADC0_RESRDY_vect)
function:VPORTB.DIR &= ~PIN2_bm; //Configure USART TX pin PB2 as input
Info: This will
configure the USART TX pin as an input. The reason behind is that, when the USART TX
pin is configured as an output, there will be a current flow between the on-chip TX
pin and the onboard EDBG pin since there are supply voltage variations between them.
By configuring it as input while there is no data transmission, unnecessary current
flow is avoided.
- 3.Program the device by clicking Debug → Start without Debugging on the top menu
window or by using the shortcut Ctrl+Alt+F5
Info: Start
Without Debugging will build the project and program the device as long as there are no
build errors.