board m52233demo problem with pins

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

board m52233demo problem with pins

跳至解决方案
1,502 次查看
jonasb
Contributor I

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.

标签 (1)
0 项奖励
回复
1 解答
741 次查看
mjbcswitzerland
Specialist V

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

 

www.uTasker.com

- OS, TCP/IP stack, USB, device drivers and simulator for M521X, M521XX, M5221X, M5222X, M5223X, M5225X. One package does them all - "Embedding it better..."

 

在原帖中查看解决方案

0 项奖励
回复
1 回复
742 次查看
mjbcswitzerland
Specialist V

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

 

www.uTasker.com

- OS, TCP/IP stack, USB, device drivers and simulator for M521X, M521XX, M5221X, M5222X, M5223X, M5225X. One package does them all - "Embedding it better..."

 

0 项奖励
回复