Changeset 82d2b68 in avrstuff


Ignore:
Timestamp:
Jul 29, 2014, 9:17:17 PM (10 years ago)
Author:
Adrien Destugues <pulkomandy@…>
Branches:
main
Children:
efe25a8
Parents:
5ef7bfc
Message:

Make baudrate computation aware of F_CPU.

git-svn-id: svn://pulkomandy.tk/avrstuff@107 c6672c3c-f6b6-47f9-9001-1fd6b12fecbe

Location:
chiptest
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • chiptest/blinkdel.hex

    r5ef7bfc r82d2b68  
    22:1000100010C00FC00EC00DC00CC00BC00AC009C07C
    33:1000200008C007C006C011241FBECFEDCDBF02D04F
    4 :1000300025C0E6CF2FE088E190E00FB6F894A895B0
     4:100030002AC0E6CF2FE088E190E00FB6F894A895AB
    55:1000400081BD0FBE21BD10BE84E083BF87B38FEF9B
    6 :1000500087BB18BA12B88AE089B988E18AB986E004
    7 :1000600083B932E024E098E4A89508B601FEFCCFFD
    8 :1000700038BF88B3822788BB9CB9F6CFF894FFCFEE
     6:1000500087BB18BA12B88DE489B9599888E18AB972
     7:1000600086E083B990E042E034E028E4A89508B641
     8:1000700001FE02C048BF9F5F9111F8CF88B383276C
     9:0A00800088BB2CB9F3CFF894FFCF32
    910:00000001FF
  • chiptest/main.c

    r5ef7bfc r82d2b68  
    1414#define LEDBIT 1 << PB2
    1515
     16#define BAUD 9600 // Safe value even for low clocks. (used by setbaud.h)
     17
    1618int main() {
    1719        wdt_enable(WDTO_2S);
    18     // configure timer 0 for a rate of 16M/(256 * 256) = ~244Hz
     20    // configure timer 0 for a rate of FCPU/(256 * 256)
    1921    TCCR0A = 0;          // timer 0 prescaler: 256
    2022        TCCR0B = 4;
     
    2527        PORTLED = 0;
    2628
    27         // Serial PORT
    28         UBRRH = 0;
    29         UBRRL = 10;
     29        // Serial baudrate - use avrlibc magic to compute the baudrate register
     30        // values.
     31        #include <util/setbaud.h>
     32        UBRRH = UBRRH_VALUE;
     33        UBRRL = UBRRL_VALUE;
     34        #if USE_2X
     35                UCSRA |= (1 << U2X);
     36        #else
     37                UCSRA &= ~(1 << U2X);
     38        #endif
    3039
     40        // Enable the serial port.
    3141        UCSRB = (1<<RXEN) |(1<<TXEN);
    3242        UCSRC = (1 << UCSZ1) | (1 << UCSZ0);
    3343
    34         while(1) {
     44        // Let's rock!
     45        uint8_t counter = 0;
     46        for(;;) {
    3547                wdt_reset();
    3648
    37 
    38                 // check timer if we need periodic reports
     49                // Wait for timer overflow...
    3950                if (TIFR & (1 << TOV0)) {
    4051                        TIFR = (1 << TOV0); // reset flag
    41                         PORTLED ^= LEDBIT;
     52                        counter++;
     53                }
    4254
    43                         UDR = 'H';
     55                if (counter == 0)
     56                {
     57                        PORTLED ^= LEDBIT; // Toggle the LED
     58                        UDR = 'H'; // Send a byte to the UART
    4459                }
    4560        }
  • chiptest/readme.txt

    r5ef7bfc r82d2b68  
    2929
    3030If everything goes well:
    31 * The LED will blink at a well-known (but currently undocumented! sorry!) rate
    32 * The character 'H' is sent to the serial port in a loop.
     31* The LED will blink at FCPU/(8^3). This should be visible for all reasonable
     32clock speeds:
     33        - 20 MHz - 0.8s
     34        - 12 MHz - 1.4s
     35        - 1 MHz - 16.8s
     36* The character 'H' is sent to the serial port at the same speed. Baudrate is
     379600 baud to be safe (it's more likely that a low baudrate can be generated
     38in a reasonably accurate way with any clock speed as a base).
Note: See TracChangeset for help on using the changeset viewer.