2024-11-29 04:38 AM
Hi everyone I'm rather new with programming with STM32 controllers and I am currently using NUCLEO-L432KC. Currently I'm facing a problem with HAL_GPIO_WritePin() function. I am interfacing with a 16x2 LCD and I am trying to write to the RS pin via the function I have mentioned, however I am facing a problem where the RS isn't being set to the desired value I am providing. I have provided the value like so: HAL_GPIO_WritePin(RS_GPIO_Port, RS_Pin, rs);
Where I have given rs = 0 but the function is setting the value as 1. I have also provided the photo of the RS pin configuration from the IOC file.
2024-11-29 04:48 AM - edited 2024-11-29 04:49 AM
Welcome to the forum!
@M0nty wrote:Hi everyone I'm rather new with programming with STM32 controllers
Do you have experience with any other microcontroller(s)? With programming in general ?
Please post your source code - instructions here:
Also your schematic of how the LCD is connected.
A good, clear photo may also help.
Have you checked the Nucleo board's User Manual and/or schematics to see that nothing else is using that pin?
2024-11-29 04:55 AM
Hello @M0nty
First let me thank you for posting.
By checking the HAL_GPIO_WritePin () the parameter :
PinState: specifies the value to be written to the selected bit.
* This parameter can be one of the GPIO_PinState enum values:
* @arg GPIO_PIN_RESET: to clear the port pin
* @arg GPIO_PIN_SET: to set the port pin
Ensure that you are passing the correct value for rs. The PinState parameter should be either
GPIO_PIN_SET or GPIO_PIN_RESET, not just 0 or 1. If you are using a variable like rs, make sure
it is defined as:
GPIO_PinState rs = GPIO_PIN_RESET; // or GPIO_PIN_SET
Instead of:
int rs = 0; // This may cause issues
THX
Ghofrane
2024-11-29 05:03 AM
@Ghofrane GSOURI wrote:The PinState parameter should be either GPIO_PIN_SET or GPIO_PIN_RESET, not just 0 or 1.e
The GPIO_PIN_SET and GPIO_PIN_RESET values are 1 and 0 - so it should be OK ...
/**
* @brief GPIO Bit SET and Bit RESET enumeration
*/
typedef enum
{
GPIO_PIN_RESET = 0U,
GPIO_PIN_SET
}GPIO_PinState;
2024-11-29 05:10 AM
Hello @M0nty and welcome to the community,
Could you please share your ioc file as well as sharing your code?
2024-11-29 05:13 AM
Hello @Andrew Neil
Let 's just try to use the parameter value as it is GPIO_PIN_SET or GPIO_PIN_RESET and see what's happen.
THX
Ghofrane