Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * PB0 - CLK
- * PB1 - RST
- *
- * USB programming:
- * https://medium.com/@paramaggarwal/programming-an-stm32f103-board-using-usb-port-blue-pill-953cec0dbc86
- * http://www.stm32duino.com/viewtopic.php?f=2&t=1920
- *
- * delay functions:
- * http://www.stm32duino.com/viewtopic.php?f=18&t=326
- * https://gist.github.com/RickKimball/8bc8228cfb6f73ccf2e9
- *
- * remapping:
- * http://www.stm32duino.com/viewtopic.php?t=2539
- * http://www.stm32duino.com/viewtopic.php?t=1224
- * http://www.stm32duino.com/viewtopic.php?t=1346
- * http://www.stm32duino.com/viewtopic.php?f=14&t=296
- *
- * without delay - clock @ ~3.6 MHz
- * delayMicroseconds(1) - FETs @ ~5.7 kHz, clock @ 400 kHz
- *
- *
- */
- const uint8 first[] = {
- 0b11111111, 0b10000001, 0b10000001, 0b10000001, 0b10000001, 0b10000001, 0b10000001, 0b11111111,
- 0b10000001, 0b10000001, 0b10000001, 0b10000001, 0b10000001, 0b10000001, 0b10000001, 0b10000001,
- 0b10000001, 0b10000001, 0b10000001, 0b10000001, 0b10000001, 0b10000001, 0b10000001, 0b10000001,
- 0b10000001, 0b10000001, 0b10000001, 0b10000001, 0b10000001, 0b10000001, 0b10000001, 0b10000001,
- 0b10000001, 0b10000001, 0b10000001, 0b10000001, 0b10000001, 0b10000001, 0b10000001, 0b10000001,
- 0b10000001, 0b10000001, 0b10000001, 0b10000001, 0b10000001, 0b10000001, 0b10000001, 0b10000001,
- 0b10000001, 0b10000001, 0b10000001, 0b10000001, 0b10000001, 0b10000001, 0b10000001, 0b10000001,
- 0b11111111, 0b10000001, 0b10000001, 0b10000001, 0b10000001, 0b10000001, 0b10000001, 0b11111111
- };
- void setup() {
- // http://www.stm32duino.com/viewtopic.php?t=1130
- afio_cfg_debug_ports(AFIO_DEBUG_SW_ONLY); // release PB3 and PB5
- pinMode(PA0, OUTPUT);
- pinMode(PA1, OUTPUT);
- pinMode(PA2, OUTPUT);
- pinMode(PA3, OUTPUT);
- pinMode(PA4, OUTPUT);
- pinMode(PA5, OUTPUT);
- pinMode(PA6, OUTPUT);
- pinMode(PA7, OUTPUT);
- pinMode(PB0, OUTPUT);
- pinMode(PB0, OUTPUT);
- pinMode(PB1, OUTPUT);
- pinMode(PB3, OUTPUT);
- pinMode(PB4, OUTPUT);
- pinMode(PB5, OUTPUT);
- pinMode(PB6, OUTPUT);
- pinMode(PB7, OUTPUT);
- pinMode(PB8, OUTPUT);
- pinMode(PB9, OUTPUT);
- pinMode(PB10, OUTPUT);
- }
- void loop() {
- //GPIOB->regs->BSRR = 0xFFFF;
- for(uint8 layer = 0; layer < 8; layer++) {
- GPIOB->regs->BRR = 0xFF << 3; // reset MOSFETs
- GPIOB->regs->BSRR = 0b1000 << layer; // enable one FET
- //GPIOB->regs->BSRR = 1 << 5; // set MOSFETs
- //delay(100);
- for(uint8 p = 0; p < 8; p++) {
- GPIOB->regs->BRR = 1; // lower clock
- delayMicroseconds(1);
- GPIOA->regs->BRR = 0xFF; // reset shift register inputs
- GPIOA->regs->BSRR = first[layer * 8 + p]; // set shift register inputs
- GPIOB->regs->BSRR = 1; // raise clock
- delayMicroseconds(1);
- }
- delayMicroseconds(1);
- //delay(20);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment