ericek111

LimCube

Oct 27th, 2017
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.76 KB | None | 0 0
  1. /*
  2.  * PB0 - CLK
  3.  * PB1 - RST
  4.  *
  5.  * USB programming:
  6.  * https://medium.com/@paramaggarwal/programming-an-stm32f103-board-using-usb-port-blue-pill-953cec0dbc86
  7.  * http://www.stm32duino.com/viewtopic.php?f=2&t=1920
  8.  *
  9.  * delay functions:
  10.  * http://www.stm32duino.com/viewtopic.php?f=18&t=326
  11.  * https://gist.github.com/RickKimball/8bc8228cfb6f73ccf2e9
  12.  *
  13.  * remapping:
  14.  * http://www.stm32duino.com/viewtopic.php?t=2539
  15.  * http://www.stm32duino.com/viewtopic.php?t=1224
  16.  * http://www.stm32duino.com/viewtopic.php?t=1346
  17.  * http://www.stm32duino.com/viewtopic.php?f=14&t=296
  18.  *
  19.  * without delay - clock @ ~3.6 MHz
  20.  * delayMicroseconds(1) - FETs @ ~5.7 kHz, clock @ 400 kHz
  21.  *
  22.  *
  23.  */
  24. const uint8 first[] = {
  25.   0b11111111, 0b10000001, 0b10000001, 0b10000001, 0b10000001, 0b10000001, 0b10000001, 0b11111111,
  26.   0b10000001, 0b10000001, 0b10000001, 0b10000001, 0b10000001, 0b10000001, 0b10000001, 0b10000001,
  27.   0b10000001, 0b10000001, 0b10000001, 0b10000001, 0b10000001, 0b10000001, 0b10000001, 0b10000001,
  28.   0b10000001, 0b10000001, 0b10000001, 0b10000001, 0b10000001, 0b10000001, 0b10000001, 0b10000001,
  29.   0b10000001, 0b10000001, 0b10000001, 0b10000001, 0b10000001, 0b10000001, 0b10000001, 0b10000001,
  30.   0b10000001, 0b10000001, 0b10000001, 0b10000001, 0b10000001, 0b10000001, 0b10000001, 0b10000001,
  31.   0b10000001, 0b10000001, 0b10000001, 0b10000001, 0b10000001, 0b10000001, 0b10000001, 0b10000001,
  32.   0b11111111, 0b10000001, 0b10000001, 0b10000001, 0b10000001, 0b10000001, 0b10000001, 0b11111111
  33. };
  34.  
  35. void setup() {
  36.   // http://www.stm32duino.com/viewtopic.php?t=1130
  37.   afio_cfg_debug_ports(AFIO_DEBUG_SW_ONLY); // release PB3 and PB5
  38.  
  39.   pinMode(PA0, OUTPUT);
  40.   pinMode(PA1, OUTPUT);
  41.   pinMode(PA2, OUTPUT);
  42.   pinMode(PA3, OUTPUT);
  43.   pinMode(PA4, OUTPUT);
  44.   pinMode(PA5, OUTPUT);
  45.   pinMode(PA6, OUTPUT);
  46.   pinMode(PA7, OUTPUT);
  47.   pinMode(PB0, OUTPUT);
  48.  
  49.   pinMode(PB0, OUTPUT);
  50.   pinMode(PB1, OUTPUT);
  51.  
  52.   pinMode(PB3, OUTPUT);
  53.   pinMode(PB4, OUTPUT);
  54.   pinMode(PB5, OUTPUT);
  55.   pinMode(PB6, OUTPUT);
  56.   pinMode(PB7, OUTPUT);
  57.   pinMode(PB8, OUTPUT);
  58.   pinMode(PB9, OUTPUT);
  59.   pinMode(PB10, OUTPUT);
  60.  
  61. }
  62.  
  63. void loop() {
  64.   //GPIOB->regs->BSRR = 0xFFFF;
  65.   for(uint8 layer = 0; layer < 8; layer++) {
  66.     GPIOB->regs->BRR = 0xFF << 3; // reset MOSFETs
  67.  
  68.     GPIOB->regs->BSRR = 0b1000 << layer; // enable one FET
  69.     //GPIOB->regs->BSRR = 1 << 5; // set MOSFETs
  70.     //delay(100);
  71.     for(uint8 p = 0; p < 8; p++) {
  72.       GPIOB->regs->BRR = 1; // lower clock
  73.       delayMicroseconds(1);
  74.       GPIOA->regs->BRR = 0xFF; // reset shift register inputs
  75.       GPIOA->regs->BSRR = first[layer * 8 + p]; // set shift register inputs
  76.      
  77.       GPIOB->regs->BSRR = 1; // raise clock
  78.       delayMicroseconds(1);
  79.     }
  80.     delayMicroseconds(1);
  81.     //delay(20);
  82.   }
  83. }
Advertisement
Add Comment
Please, Sign In to add comment