This section covers more advanced debugging topics with Studio 7 both as video (linked below) and hands-on document. The main topics are how to modify variables in the code, conditional- and action-breakpoints, as well as memory view.
uint8_t SW_get_state(void) { static uint8_t SW0_prv_state = 0; static uint8_t SW0_edge_count = 0; uint8_t SW0_cur_state = !(PORTB.IN & PIN5_bm); /* Read the current SW0 state */ if (SW0_cur_state != SW0_prv_state) /* Check for edges */ { SW0_edge_count++; } SW0_prv_state = SW0_cur_state; /* Keep track of previous state */ /* * Report the switch as pushed when it is pushed or the edge counter is a * multiple of 3 */ return SW0_cur_state || !(SW0_edge_count % 3); }
A variable can also be added to the Watch window by clicking on an empty field name and typing the variable name. This way, it is even possible to cast a variable to a different data type for better readability in the Watch window. This is especially useful if it is required to look at an array that is passed to a function as a pointer.
*(uint8_t (*)[<n>])<name_of_array_pointer>Where <n> is the number of elements in the array and <name_of_array_pointer> is the name of the array to be examined.
*(uint8_t (*)[5])&SW0_edge_countNote that the '&' symbol must be used in this case to obtain a pointer to the variable.
This section is a guide to using Atmel Studio to place conditional breakpoints.
((SW0_edge_count % 5) == 0) && SW0_cur_state
This section is a guide to using Atmel Studio to place action breakpoints.
Prv state:{SW0_prv_state}, Cur_state:{SW0_cur_state}, Edge count:{SW0_edge_count}
Code used for conditional- and action-breakpoints.
#include <avr/io.h> #include <avr/interrupt.h> void LED_on(); void LED_off(); uint8_t SW_get_state(); void LED_set_state(uint8_t SW_state); int main(void) { PORTB.DIRSET = PIN4_bm; PORTB.OUTSET = PIN4_bm; PORTB.PIN5CTRL |= PORT_PULLUPEN_bm | PORT_ISC_BOTHEDGES_gc; sei(); while (1) { } } #pragma region LED_functions void LED_on() { PORTB.OUTCLR = PIN4_bm; //LED on } void LED_off() { PORTB.OUTSET = PIN4_bm; //LED off } void LED_set_state(uint8_t SW_state) { if (SW_state) { LED_on(); } else { LED_off(); } } #pragma endregion LED_functions uint8_t SW_get_state(void) { static uint8_t SW0_prv_state = 0; static uint8_t SW0_edge_count = 0; uint8_t SW0_cur_state = !(PORTB.IN & PIN5_bm); /* Read the current SW0 state */ if (SW0_cur_state != SW0_prv_state) /* Check for edges */ { SW0_edge_count++; } SW0_prv_state = SW0_cur_state; /* Keep track of previous state */ /* * Report the switch as pushed when it is pushed or the edge counter is a * multiple of 3 */ return SW0_cur_state || !(SW0_edge_count % 3); } ISR(PORTB_PORT_vect) { uint8_t intflags = PORTB.INTFLAGS; PORTB.INTFLAGS = intflags; uint8_t SW_state = SW_get_state(); LED_set_state(SW_state); }