Skip to content

Instantly share code, notes, and snippets.

@electronut
Last active October 29, 2017 08:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save electronut/f4e158d7de38b1f58c90b165ec5e3c71 to your computer and use it in GitHub Desktop.
Save electronut/f4e158d7de38b1f58c90b165ec5e3c71 to your computer and use it in GitHub Desktop.
stm32-returns-5.c
// send 16 bit data packet
void MAX7219::sendPacket(MAX7129_REG reg, uint8_t data)
{
// CS
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_1, GPIO_PIN_RESET);
//uint16_t packet = (reg << 8) | data;
uint8_t packet[2];
packet[0] = reg;
packet[1] = data;
HAL_SPI_Transmit(const_cast<SPI_HandleTypeDef*>(_hSPI), (uint8_t*)&packet, 2, 100);
// CS
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_1, GPIO_PIN_SET);
}
// set the whole display with an 8x8 buffer
void MAX7219::setBuffer(const BitBuf88& buf)
{
for (int j = 0 ; j < 8; j++) {
sendPacket(static_cast<MAX7129_REG>(j+1), buf._vals[j]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment