This example is so simple I can not see why it does not work!
It just loops reading a pin table from gpio:read and extracts the values and prints them.
They all come up as 1
any ideas?
I am running MQX 3.6 on a mcf52259demo board.
I have the gpio pins wired on J4 so I can pull the up/down and watch for changes
Code below... (and attached if you want to compile)
tom
/*TASK*-----------------------------------------------------------------** Function Name : Main_task* Comments :* This task initializes RTCS and starts SHELL.**END------------------------------------------------------------------*/TASK_TEMPLATE_STRUCT MQX_template_list[] ={/* Task number, Entry point, Stack, Pri, String, Auto? */ {MAIN_TASK, Main_task, 3000, 9, "main", MQX_AUTO_START_TASK, 0, 50}, {0, 0, 0, 0, 0, 0, 0, 0}};#define GPIO_W1 GPIO_PORT_TA | GPIO_PIN3#define GPIO_W0 GPIO_PORT_TA | GPIO_PIN2#define GPIO_H1 GPIO_PORT_TA | GPIO_PIN1#define GPIO_H0 GPIO_PORT_TA | GPIO_PIN0#define GPIO_D7 GPIO_PORT_AN | GPIO_PIN7#define GPIO_D6 GPIO_PORT_AN | GPIO_PIN6#define GPIO_D5 GPIO_PORT_AN | GPIO_PIN5#define GPIO_D4 GPIO_PORT_AN | GPIO_PIN4#define GPIO_D3 GPIO_PORT_AN | GPIO_PIN3#define GPIO_D2 GPIO_PORT_AN | GPIO_PIN2#define GPIO_D1 GPIO_PORT_AN | GPIO_PIN1#define GPIO_D0 GPIO_PORT_AN | GPIO_PIN0#define GPIO_J16 GPIO_PORT_TC | GPIO_PIN2#define GPIO_J17 GPIO_PORT_TC | GPIO_PIN1#define GPIO_FLIP GPIO_PORT_UC | GPIO_PIN3#define GPIO_RESET GPIO_PORT_TC | GPIO_PIN3#define GPIO_SYNC GPIO_PORT_NQ | GPIO_PIN1MQX_FILE_PTR inputfd;static GPIO_PIN_STRUCT pins_input[] = { GPIO_W1, GPIO_W0, GPIO_H1, GPIO_H0, GPIO_D7, GPIO_D6, GPIO_D5, GPIO_D4, GPIO_D3, GPIO_D2, GPIO_D1, GPIO_D0, GPIO_J16, GPIO_J17, GPIO_LIST_END};int bin_pins(GPIO_PIN_STRUCT pins[], int bits);void Main_task(uint_32 initial_data){ int w, h, J16, J17; volatile MCF5225_STRUCT _PTR_ reg_ptr = _PSP_GET_IPSBAR(); volatile MCF5225_GPIO_STRUCT _PTR_ gpio = ®_ptr->GPIO; // TA0-3 Inputs inputfd = fopen("gpio:input", (char *)&pins_input); if (inputfd == NULL) { printf("Error opening GPIO Files!\r\n"); _task_block(); } printf("GPIO Opened ok\r\n"); while (1) { w = h = 1; if (ioctl(inputfd, GPIO_IOCTL_READ, &pins_input) == IO_OK) { w = bin_pins(&pins_input[0], 2) + 1; h = bin_pins(&pins_input[2], 2) + 1; J16 = bin_pins(&pins_input[12], 1); J17 = bin_pins(&pins_input[13], 1); } printf("H %d W %d J16 %d J17 %d PORTTA %x DDR %x PAR %x PORTTAP %x\r\n", h, w, J16, J17, gpio->PORTTA, gpio->DDRTA, gpio->PTAPAR, gpio->PORTTAP_SETTA); _time_delay(1000); }}
已解决! 转到解答。
BTW The printf generates the following output
H 4 W 4 J16 1 J17 1 PORTTA f DDR 0 PAR 0 PORTTAP fH 4 W 4 J16 1 J17 1 PORTTA f DDR 0 PAR 0 PORTTAP fH 4 W 4 J16 1 J17 1 PORTTA f DDR 0 PAR 0 PORTTAP fH 4 W 4 J16 1 J17 1 PORTTA f DDR 0 PAR 0 PORTTAP f
DDR 0 = Outputs, PARTA = 0 GPIO, Output reg F and Pin (PORTTAP) F
sigh
I sure hope it is stupid... those are easy to fix ![]()
(blush)
It turns out the pin on J4 that I was using to pull down the other ones, was not ground.
Well it was a simple solution!
Thanks for the public embarassment!
I guess that is the price we pay for asking for help publically!
![]()