Teensy 3.0: which variable-declaration for registers?

Status
Not open for further replies.

dave

Active member
Hi
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:
Code:
 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
 
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.
 
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:
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!

Thanks
 
Status
Not open for further replies.
Back
Top