Hey how can I change that some pins are output and some pins are input
I want TIN0, TIN1, TIN2, TIN3 and IRQ7 set as input.
and I want AN0, AN1, AN2, AN3, AN4, AN5, AN6 and AN7 set as output.
and how do I assigned a name for these pins by example TIN0 ==> switch 1.
Solved! Go to Solution.
Hi
Most pins default to GPIO input with pull up resistor (around 25k). This means that TIN0..TIN3 don't need to be further configured to be used as input - simply read value from the SETTC register.
The IRQ inputs are an exception since they default to IRQ and not GPIO. To set to GPIO clear the bits 0xc000 in PNQPAR. This is then an input and can be read as bit 0x80 in the SETNQ register.
To set the AN port to all outputs write 0xff to the data direction register DDRAN. Then control their values by writing to the PORTAN register. [Alternatively to sets bit use SETAN, with a '1' at the bit(s) to be set, alternatively to clear bits use CLRAN, with '0' at the bits(s) to be cleared].
To read from TIN0 with the name SWITCH1 use a define
#define SWITCH1 0x01
then
switch_state = ((SWITCH1 & SETTC) != 0); // 1 when '1' and 0 when '0'
Please read chapter 14 of the M52235 user's manual for full details about using GPIOs.
Regards
Mark
- OS, TCP/IP stack, USB, device drivers and simulator for M521X, M521XX, M5221X, M5222X, M5223X, M5225X. One package does them all - "Embedding it better..."
Hi
Most pins default to GPIO input with pull up resistor (around 25k). This means that TIN0..TIN3 don't need to be further configured to be used as input - simply read value from the SETTC register.
The IRQ inputs are an exception since they default to IRQ and not GPIO. To set to GPIO clear the bits 0xc000 in PNQPAR. This is then an input and can be read as bit 0x80 in the SETNQ register.
To set the AN port to all outputs write 0xff to the data direction register DDRAN. Then control their values by writing to the PORTAN register. [Alternatively to sets bit use SETAN, with a '1' at the bit(s) to be set, alternatively to clear bits use CLRAN, with '0' at the bits(s) to be cleared].
To read from TIN0 with the name SWITCH1 use a define
#define SWITCH1 0x01
then
switch_state = ((SWITCH1 & SETTC) != 0); // 1 when '1' and 0 when '0'
Please read chapter 14 of the M52235 user's manual for full details about using GPIOs.
Regards
Mark
- OS, TCP/IP stack, USB, device drivers and simulator for M521X, M521XX, M5221X, M5222X, M5223X, M5225X. One package does them all - "Embedding it better..."