Test application for getting the Nucleo F0 30 board to work with Evan's prototype LED board.

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
bgrissom
Date:
Fri Jul 11 21:10:04 2014 +0000
Parent:
2:a57a5501152c
Child:
4:4eeacb39a417
Commit message:
LEDs light up! Commiting before a bit of debugging and then I'll clean up the code.

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Fri Jul 11 15:37:30 2014 +0000
+++ b/main.cpp	Fri Jul 11 21:10:04 2014 +0000
@@ -8,8 +8,11 @@
 int  cmd_S0(uint16_t value);
 void cmd_S1(void);
 
+// Globals
 bool gSpiMode = false;
 SPI* gSpiPtr = NULL;
+DigitalOut gbbTRANS(D8); // Global bit bang TRANS (data) line
+
 
 int main() {
     // NOTE: 24MHz is half the 48MHz clock rate.  The PWM registers
@@ -21,26 +24,27 @@
     //       50% duty cycle (which seems to be right for the SPI clock
     //       line as well as a reasonable choice for the PWM line).
 
+    // BAG ORIG: gbbTRANS = 1; // Start with TRANS high.  It acts like a SPI slave select
+                  // that is active-low.
+    gbbTRANS = 0;
 
-    /////////////////////////////////////////////////
-    //               PWMCLK
-    /////////////////////////////////////////////////
+    // PWMCLK
     pwmout_t outs;
     pwmout_init(&outs, D9);
-    //pwmout_period_ns(&outs, 2); // 24 MHz (not very clean on the scope)
-    pwmout_period_ns(&outs, 40); // 
+    pwmout_period_ns(&outs, 2); // 24 MHz (not very clean on the scope)
+    //pwmout_period_ns(&outs, 40); // 1.2 MHz on the scope
     pwmout_write(&outs, 0.5f);
 
-
     int ret = OK; // Return value
     int i = 0;
 
-    printf("17:32\n");
+    printf("14:53\n");
 
     while (1) {
         //wait_ms(50);
         for (i=0; i<16; i++) {
-            ret = cmd_S0(0x0003);
+            ret = cmd_S0(0x00FF);
+            // ORIG: ret = cmd_S0(0xFFFF);
             if (ret != OK) {
                 printf("ERROR cmd_S0()\n");
                 return ERROR;
@@ -51,33 +55,6 @@
 }
 
 
-// This code is based off:
-// mbed/libraries/mbed/targets/hal/TARGET_STM/TARGET_NUCLEO_F030R8/pwmout_api.c  pwmout_period_us()
-void pwmout_period_ns(pwmout_t* obj, int us) {
-    TIM_TypeDef *tim = (TIM_TypeDef *)(obj->pwm);
-    TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
-    float dc = pwmout_read(obj);
-
-    TIM_Cmd(tim, DISABLE);
-
-    obj->period = us;
-
-    TIM_TimeBaseStructure.TIM_Period = obj->period - 1;
-    // Orig code:  TIM_TimeBaseStructure.TIM_Prescaler = (uint16_t)(SystemCoreClock / 1000000) - 1; // 1 µs tick
-    TIM_TimeBaseStructure.TIM_Prescaler = 0;  // BAG 1 ns tick (?)
-    TIM_TimeBaseStructure.TIM_ClockDivision = 0;
-    TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
-    TIM_TimeBaseInit(tim, &TIM_TimeBaseStructure);
-
-    // Set duty cycle again
-    pwmout_write(obj, dc);
-
-    TIM_ARRPreloadConfig(tim, ENABLE);
-
-    TIM_Cmd(tim, ENABLE);
-}
-
-
 
 // S0 Command:
 //      Needs only SCK and SIN (which are SPI_SCK and SPI_MOSI respectively).
@@ -103,11 +80,15 @@
             // For a graphical reminder on polarity and phase, visit:
             //     http://www.eetimes.com/document.asp?doc_id=1272534
             gSpiPtr->format(16, 0);
-            gSpiPtr->frequency(1000000);  // 1  MHz
-            //gSpiPtr->frequency(24000000); // 24 MHz
+            //gSpiPtr->frequency(1000000);  // 1.5 MHz on the scope
+            gSpiPtr->frequency(24000000); // 24 MHz
             gSpiMode = true;
         }
+        gbbTRANS = 0; // Like an SPI slave select
         gSpiPtr->write(value);
+        gbbTRANS = 1; // Like an SPI slave select
+        wait_us(1);
+        gbbTRANS = 0; // Set back low
         return OK;
 }
 
@@ -117,6 +98,8 @@
     int i = 0;
     int j = 0;
     
+    gbbTRANS = 0; // FIXME
+    
     if ( gSpiMode == true &&
          gSpiPtr  != NULL)
     {
@@ -126,10 +109,9 @@
     }
     
     DigitalOut bbSCK (D13); // bit bang clock
-    DigitalOut bbTRANS(D8); // bit bang TRANS (data) line
 
-    bbSCK   = 0; // Start off/low
-    bbTRANS = 1; // Set high
+    bbSCK    = 0; // Start off/low
+    gbbTRANS = 1; // Set high
 
     // Loop 6 times = 3 clock cycles
     for (j=0; j<6; j++) { // Always use an even number here!
@@ -137,8 +119,33 @@
         i == 0 ? i = 1 : i = 0;          // Toggle i
         i == 0 ? bbSCK = 0 : bbSCK = 1;  // Set SCK to the same value as i
     }
-    bbTRANS = 0; // Set low
+    gbbTRANS = 0; // Set low
 }
 
 
 
+// This code is based off:
+// mbed/libraries/mbed/targets/hal/TARGET_STM/TARGET_NUCLEO_F030R8/pwmout_api.c  pwmout_period_us()
+void pwmout_period_ns(pwmout_t* obj, int us) {
+    TIM_TypeDef *tim = (TIM_TypeDef *)(obj->pwm);
+    TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
+    float dc = pwmout_read(obj);
+
+    TIM_Cmd(tim, DISABLE);
+
+    obj->period = us;
+
+    TIM_TimeBaseStructure.TIM_Period = obj->period - 1;
+    // Orig code:  TIM_TimeBaseStructure.TIM_Prescaler = (uint16_t)(SystemCoreClock / 1000000) - 1; // 1 µs tick
+    TIM_TimeBaseStructure.TIM_Prescaler = 0;  // BAG 1 ns tick (?)
+    TIM_TimeBaseStructure.TIM_ClockDivision = 0;
+    TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
+    TIM_TimeBaseInit(tim, &TIM_TimeBaseStructure);
+
+    // Set duty cycle again
+    pwmout_write(obj, dc);
+
+    TIM_ARRPreloadConfig(tim, ENABLE);
+
+    TIM_Cmd(tim, ENABLE);
+}