Code: Select all
void WriteData(uint8_t data)
{
uint32_t pupdr = GPIOB->PUPDR;
GPIOB->PUPDR = pupdr & 0xFFFF0000; // no pull on bits 0 to 7;
GPIOB->OTYPER |= 0xFF; // set to open drain - can this be done once?
GPIOB->MODER = (GPIOB->MODER & 0xFFFF0000) | 0x5555; // set to output
GPIOB->ODR = (GPIOB->ODR & 0xFF00) | data;
// Maybe flash ack here?
GPIOB->OTYPER &= ~(0xFF); // reset to non-open drain (why?)
GPIOB->MODER = (GPIOB->MODER & 0xFFFF0000); // set to input
GPIOB->PUPDR = pupdr; // restore
// do this inline to avoid function call overhead
GPIOC->BSRR = GPIO_PIN_11 << 16; // set
GPIOC->BSRR = GPIO_PIN_11; // reset
}
Also you shouldnt need to change the state of the pull ups between read and write. so that could maybe go away too.
I would honestly avoid using the HAL as its dog slow and its not really all that hard to write the routines you want.

