info:avr32_gpio_writing
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
info:avr32_gpio_writing [2009/04/27 13:36] – created tomgee | info:avr32_gpio_writing [2009/04/29 09:59] (current) – tomgee | ||
---|---|---|---|
Line 4: | Line 4: | ||
For the UC3A0512, read the pin value register and then write to the output value register. | For the UC3A0512, read the pin value register and then write to the output value register. | ||
- | //Set the output value of PORT0\\ | ||
- | AVR32_GPIO.port[ 0 ].ovrs = value ; | ||
- | //Clear the output value of PORT0\\ | ||
- | AVR32_GPIO.port[ 0 ].ovrc = value ; | ||
- | //Read the port pins\\ | ||
- | value = AVR32_GPIO.port[ 0 ].pvr ; | ||
+ | // Set the output value of PORT0 \\ | ||
+ | | ||
+ | // | ||
+ | | ||
- | You can also use the .ovr function: | + | // |
+ | value = AVR32_GPIO.port[ 0 ].pvr ; \\ | ||
- | Example PORT0 has the value 0xAAFF55FF | + | You can also use the .ovr function:\\ |
- | And if i do AVR32_GPOI.port[0].ovr = 0x55AAFFBB; | + | Example PORT0 has the value 0xAAFF55FF\\ |
- | then all the bits will change, because if you use the ovrs or ovrc you can only change set or clear. | + | |
+ | |||
+ | then all the bits will change, because if you use the ovrs or ovrc you can only change set or clear. \\ | ||
+ | |||
+ | Look at the user manual page 44 you will find the PORTA, PORTB, PORTC and PORTX to GPIO mapping. | ||
+ | |||
+ | These GPIOs are divided in 32 bit ports or registers. This division is called as PORT0, PORT1, and so forth. While selecting any pin functionality, | ||
+ | The registers related to these ports are GPER, PMR0, PMR1 etc. | ||
+ | |||
+ | To select a particular pin as gpio, for example PORTB.0. Goto to page 44, the GPIO mapping is 32. Hence, it is PORT1.0. So, set the LSB of PORT1 GPER register. | ||
+ | |||
+ | On page 174 you will find the PORT0, PORT1, etc offsets from the base address. Section 22.5 from the user manual explains it all. | ||
+ | |||
+ | If you want to set one or even more bits at a port you can use | ||
+ | OVRS = (Bit(x) | Bit(y)); | ||
+ | with | ||
+ | # | ||
+ | If you want to clear some bits just use | ||
+ | OVRC = Bit(z); | ||
+ | If you just want to toggle one or more bits use | ||
+ | OVRT = Bit(x); and this bit has the inverted level without influencing the others during that operation. | ||
+ | If you want to set some bits to a specific value like for your display port you can also use toggle instead of clearing all and setting the used ones like | ||
+ | OVRT = (OVR & AllBitMask) ^ (NewValue << Offset); | ||
+ | Here you used the read function as well as the toggle function and set all bits simultaneously, | ||
+ | |||
+ | The GPER(S/C/T) is used logically the some way to use a port pin as a port pin or not. If you clear it the port pin is connected to one of the internal modules like USART, TWI, SPI or Timer. You have to set GPER to use a port pin as a port pin. But don't forget to set the output driver too. Otherwise you have a port pin but you output value is not driven. | ||
+ | If you want a pure output you should also clear the ODMER otherwise you have an open drain driver if the device is populated with it.\\ | ||
+ | And last but not least you should also clear the PUER to keep your power consumption low. | ||
+ | |||
+ | ===== Setting Clock ===== | ||
+ | |||
+ | pm_freq_param_t osc; | ||
+ | osc.cpu_f = 66000000; | ||
+ | osc.osc0_f = FOSC0; | ||
+ | osc.osc0_startup = FOSC0_STARTUP; | ||
+ | osc.pba_f = 33000000; | ||
+ | pm_configure_clocks(& | ||
+ | |||
+ | |||
+ | You can set and reset the port pins directly. Here is an example for PORTB: | ||
+ | Code: | ||
+ | volatile avr32_gpio_port_t *gpio_port_b = ( volatile avr32_gpio_port_t * ) & | ||
+ | |||
+ | gpio_port_b-> | ||
+ | gpio_port_b-> | ||
+ | |||
+ | |||
+ | ===== Setting PIO Faster ===== | ||
+ | |||
+ | This is faster, because you don't have to call a function (saving and restoring of all registers => stack). | ||
+ | |||
+ | If you want to set or reset a pin of PORTA: | ||
+ | |||
+ | volatile avr32_gpio_port_t *gpio_port_a = ( volatile avr32_gpio_port_t * ) & | ||
+ | |||
+ | gpio_port_a-> | ||
+ | gpio_port_a-> | ||
+ | |||
+ | |||
+ | You can also set or reset more than one pin at the same time. |
info/avr32_gpio_writing.1240853783.txt.gz · Last modified: 2009/04/27 13:36 by tomgee