Using Code Instrumentation

Finally, in this section we will look at some other tricks which the Data Visualizer is capable of.

Aside from taking current measurements, the Power Debugger has a full Data Gateway Interface (DGI) port for streaming data from the target to the host computer. We will hook this up to the USART for simple console output.

Some hardware wiring needs to be done to link the USART. We use Synchronous mode for convenience in baud rate setting.
The updated wiring diagram is shown here:

The example code makes use of the pin-change interrupt connected to the button on the Xplained Mini to toggle a LED and update a ticker. On each button-press the LED toggles and the ticker count is sent using the DGI USART along with a LED status message.

The code below is included in project low_power_105.

#include<avr/io.h>#include<avr/interrupt.h>#include<avr/sleep.h>volatile uint8_t led_on;volatile uint8_t send_message;volatile uint8_t ticker =0;constchar* message_on ="LED ON ";constchar* message_off ="LED OFF ";

ISR (PCINT0_vect){// Each botton press generates two pin-change interrupt (press, release)// Ignore half of theseif(PINB &(1<<7))return;// Update LEDif(led_on)
        PORTB &=~(1<<5);else
        PORTB |=(1<<5);// Invert led_on
    led_on =~led_on;// Flag a message send
    send_message =1;// Increment ticker
    ticker++;// Reset tickerif(ticker >=10)
        ticker =0;}void usart_send (constchar data){// Send a character to the USART
    UDR0 = data;// Wait for the character to be sentwhile(!(UCSR0A &(1<< TXC0)));// Clear the flag
    UCSR0A =(1<< TXC0);}intmain(void){// PORTB5 to output
    DDRB =(1<<5);// LED OFF
    PORTB =0;
    led_on =0;// Enable Pin-change interrupt
    PCICR =(1<< PCIE0);
    PCMSK0 =(1<< PCINT7);// USART0// Baud trivial in synchronous mode    
    UBRR0 =0x0FFF;// Enable XCK for master clock outout
    DDRD |=(1<<4);// Enable USART transmitter
    UCSR0B |=(1<< TXEN0);// Synchronous mode
    UCSR0C |=(1<< UCSZ01)|(1<< UCSZ00)|(1<< UMSEL00);// Interrupts onsei();while(1){// Sleepset_sleep_mode(SLEEP_MODE_IDLE);sleep_mode();// Woken upif(send_message){// Send a messageconstchar* pmessage;if(led_on)
                pmessage = message_on;else
                pmessage = message_off;while(*pmessage)usart_send(*pmessage++);// Send the ticker valueusart_send(ticker +'0');usart_send('\n');// Sent
            send_message =0;}}}
Todo:
  • Build the project/solution (F7)
  • Program the application into the target device using Start Without Debugging (Ctrl+Alt+F5)
  • Switch to Data Visualizer to see the results