0
I am using STM32F103 ,CUBE IDE with HAL library , I am trying to write the outport as giving a 4 bit value to the entire port (16bit ) By using a shift bit operator . Can I directly apply that data to the port as follows. GPIO_PORTA |= 0x0ff; Like wise Or how to write it
There's no HAL_GPIO function to manipulate multiple pins at once. Instead you'll use GPIO register read and write instructions, as suggested.By using HAL Library ,
How to put data as follows
GPIOA->ODR = 0xABCD;
Then GPIOA->ODR = 0xABCD; is it wrong idea ,May i need to write each bitfield one by one ?There's no HAL_GPIO function to manipulate multiple pins at once. Instead you'll use GPIO register read and write instructions, as suggested.
You don't necessarily manually code the and/or operations to write part of a register. After defining a respective structure, the compiler can take care of it.
For writing 16 bit of data to GPIOA->ODR at once, the instruction is correct, because GPIOx_ODR register uses only 16 bit and requires the upper word to be set to 0. But you have been asking how to write 4/8/16 bit data, so it's not the general solution.Then GPIOA->ODR = 0xABCD; is it wrong idea ,May i need to write each bitfield one by one ?
GPIO->ODR = (GPIO->ODR & 0x0fff) | (cmd & 0xf000);
void LCD_cmd(__uint16_t cmd)
{ HAL_GPIO_WritePin(GPIOB,GPIO_PIN_11, GPIO_PIN_RESET);
cmd = (cmd << 8) ;
GPIOB->ODR = 0xf000 & cmd;
LCD_Strobe();
GPIOB->ODR = (GPIOB->ODR & 0x0fff) | (cmd & 0xf000);
HAL_GPIO_WritePin(GPIOB,GPIO_PIN_11, GPIO_PIN_RESET);
cmd = (cmd << 4) ;
GPIOB->ODR = 0xf000 & cmd;
LCD_Strobe();
GPIOB->ODR = (GPIOB->ODR & 0x0fff) | (cmd & 0xf000);
}
}
void LCD_cmd(__uint16_t cmd)
{
cmd = (cmd << 8) ;
GPIOB->ODR = (GPIOB->ODR & 0x0fff) | (cmd & 0xf000);
LCD_Strobe();
cmd = (cmd << 4) ;
GPIOB->ODR = (GPIOB->ODR & 0x0fff) | (cmd & 0xf000);
LCD_Strobe();
}
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?