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
2024-11-29 08:22 PM
I have also tried the same thing by substituting rs as GPIO_PIN_RESET but the same issue occurs
2024-11-29 08:24 PM - edited 2024-11-29 08:55 PM
2024-11-29 08:49 PM - edited 2024-11-29 10:04 PM
I am actually passing rs as an argument from a function call as shown so I'm not sure if this also causes a problem. (Edit: I tried changing the type of argument for rs from int to GPIO_PinState: void send_cmd(char data, GPIO_PinState rs) but this also doesn't work and the same problem occurs.
send_cmd(0x38,0);
void send_cmd (char data, int rs)
{
HAL_GPIO_WritePin(RS_GPIO_Port, RS_Pin, rs);
}
.
2024-11-30 01:42 AM
Time to go back to basics.
Disconnect the LCD.
Go back to a basic "blinky" program which just toggles the LED on the Nucleo board - just a loop with inline delays.
Once that is working, change it to toggle your RS pin.
Does the pin toggle?