Digital port read problem

Fully featured ARM compilers available on Windows, Linux, and macOS.
Post Reply
Author
Message
d_scheider
Posts: 7
Joined: 02 Dec 2022 16:27

Digital port read problem

#1 Post by d_scheider » 21 Mar 2023 15:09

I'm unable to read from a GPIO port using the PORT driver. This is the code that I'm using:

port_init( &port, PORT_B, 0xFFFF, PIN_DIRECTION_DIGITAL_INPUT );
read_value = port_read(&port);
uint16_to_str( read_value, OutputString);
main_screen.RoundedButton_0 -> text.caption = OutputString;
vtft_draw_component(_vtft, (vtft_component*)(main_screen.RoundedButton_0));

It compiles and runs, but always returns a value of 0 regardless of input. I know my hardware is working, because this code works perfectly fine for output:

Count++;
port_init( &port, PORT_A, 0xFFFF, PIN_DIRECTION_DIGITAL_OUTPUT );
port_write( &port, Count );

Smart_Aleck
Posts: 16
Joined: 07 Feb 2023 20:45

Re: Digital port read problem

#2 Post by Smart_Aleck » 21 Mar 2023 20:51

Hi,

isn't it that "port" is a struct, which also cońtains the port name like PORT_B or PORT_A.

So, if you use the same structure for two different ports, I think this might go wrong.
I can't test it here, but I propose to try something like this:

Code: Select all

// Port driver context structure.
static port_t port_a, port_b ;

port_init( &port_b, PORT_B, 0xFFFF, PIN_DIRECTION_DIGITAL_INPUT );
read_value = port_read(&port_b);
uint16_to_str( read_value, OutputString);
main_screen.RoundedButton_0 -> text.caption = OutputString;
vtft_draw_component(_vtft, (vtft_component*)(main_screen.RoundedButton_0));

Count++;
port_init( &port_a, PORT_A, 0xFFFF, PIN_DIRECTION_DIGITAL_OUTPUT );
port_write( &port_a, Count );
BR
SA

Post Reply

Return to “PIC32 AI Compilers”