Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 3 of 3

Thread: Teensy 3.0: which variable-declaration for registers?

  1. #1

    Teensy 3.0: which variable-declaration for registers?

    Maybe it sound like a noob question but I really need some help to solve this problem.
    Let s say I need to copy in a variable the following Register:
     register_var = GPIOC_PDIR;
    to perform later some bit-calculations (and not mathematical operations).

    How should I declare my register_var variable!??!
    GPIOC_PDIR is (accoridng to the datasheet) a 32bits register and the declaration byte is giving me some trouble.
    I m not sure that using uint32_t is right.

    Could you please help me?
    Thank you very much

  2. #2
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    uint32_t generally works very well for storing 32 bits from a 32 bit register.

    If your code has something special going on, this general advice might not apply? It's hard to give more specific advise without seeing the actual code....

    Regarding bit calculations on I/O ports, you might also read this caution about interfering with I/O from interrupts.

  3. #3
    Thanks Paul, I didn t know that link.
    I thought that reading from an Interrupt routine should not be a problem, since register for writing and reading different are.

    Here my code:
        // This ISR routine triggers when an event occurs. This could happen the channel CH0
        // changes level. 
        if( FTM0_C0SC & 0x80 ) {
            // If on channel CH0 is raising edge (TTL = 1)
            if( ( GPIOC_PDIR & 0b0000000000000010 ) ) {
                // ...dann reset counter to zero
                FTM0_CNT = 0x00;
            } else {
                // ...otherwise check if there is a failing edge on the line and now TTL = 0
                // in this case read the timer for CH0
                if( ( ( GPIOC_PDIR & 0b0000000000000010 ) ^ 0b0000000000000010 ) ) {
                    // read and convert the result in microseconds
                    tempRegister = ( FTM0_C0V * 1000000 ) / 15625;
                    // and then check if received datas are in the right interval
                    if( ( tempRegister > MIN_PULSE_RX ) && (tempRegister < MAX_PULSE_RX ) ) {
                        // ...when in the right spektrum save data in the struct
                        dataServo.throttlePulse = tempRegister;
        // clear channel interrupt flag (CHF) before exiting
        FTM0_C0SC &= ~( 0x80 );
    Using uint32_t as a "container" for the register works without problems!


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts