2022-05-19 10:23 AM
2022-05-19 10:24 PM
Hello. You can refer to one of our sessions where we demonstrate different coding methods without and with library usage. It is "Moving from 8 to 32 bits workshop".(especially part 7).
2022-05-20 02:27 AM
You change state of a pin's output by writing to GPIOx_BSRR (which atomically changes GPIOx_ODR), so if LED is on e.g. PB4 you'd write something like
GPIOB->BSRR = 1 << 4; // set
delay_ms(200);
GPIOB->BSRR = 1 << (4 + 16); // clear
delay_ms(200); // if you don't put a delay after clear, you will not see LED blinking
There are macros in the device header, which may or may not be useful (I won't write the delay):
GPIOB->BSRR = GPIO_BSRR_BS4; // set
GPIOB->BSRR = GPIO_BSRR_BR4; // clear
Now you can write your own macros to change pins. This is something developers do themselves to their own liking. For example, I use the following:
#define PIN_SET(pin) pin##_PORT->BSRR = (1 << (pin##_PIN + 0))
#define PIN_CLR(pin) pin##_PORT->BSRR = (1 << (pin##_PIN + 16))
#define PIN_GET(pin) ((pin##_PORT->IDR & (1 << pin##_PIN)) ? 1 : 0)
then in program
#define LED_PORT GPIOB
#define LED_PIN 4
PIN_SET(LED);
PIN_CLR(LED);
but there are many other ways to tackle this.
JW
2022-05-20 04:45 AM
2022-05-23 05:06 AM
THANKS, I GO TO READ
2022-05-23 05:23 AM
Hi, i understand the register BSRR and ODR for wirte output, but i want define BSRR or ODR with name LED, and set or clear using LED.
LED =1; // set ODR in 1.
LED =o; // clear ODR in 0.
i have example with stm8 with this macro:
#define led PD_ODR_ODR4
#define led_dir PD_DDR_DDR4
#define led_Push PD_CR1_C14
#define led_fast PD_CR2_C24
....
.
.
.
void inicializar_pin(void){
led_dir = 1; // Port D, bit 4 is output.
led_Push = 1; // Pin is set to Push-Pull mode.
led_fast = 1;
}
// using the port:
led=1;
delay(200);
led=0;
delay(200);
i read macro stm32 in c, but i don´t find a macro how this,and i am doing but i have error compile. i don´t can modify ODR register using led=1.