• TLV2553 - CCS

    jlbrian711/02/2016 at 14:56 0 comments

    //Will Yates - NeoPixel_Simple
    #include <stdint.h>
    #include <stdbool.h>
    
    #include "inc/hw_gpio.h"
    #include "inc/hw_ints.h"
    #include "inc/hw_types.h"
    #include "inc/hw_memmap.h"
    #include "inc/hw_ssi.h"
    
    //#define PART_TM4C123GH6PM
    
    #include "driverlib/pin_map.h"
    #include "driverlib/qei.h"
    #include "driverlib/gpio.h"
    #include "driverlib/sysctl.h"
    #include "driverlib/rom.h"
    #include "driverlib/ssi.h"
    #include "driverlib/udma.h"
    
    //*****************************************************************************
    
    #define NUM_LED 6
    #define LED_PORT GPIO_PORTA_BASE
    #define LED_PIN GPIO_PIN_7
    #define TLV2553_PORT GPIO_PORTE_BASE
    #define TLV2553_CS GPIO_PIN_0
    #define TLV2553_EOC GPIO_PIN_5
    #define NRF24_PORT GPIO_PORTA_BASE
    #define NRF24_CSN GPIO_PIN_4
    #define NRF24_CE GPIO_PIN_3
    #define NRF24_IRQ GPIO_PIN_2
    
    // TLV2553 Commands
    uint32_t chan_0  = 0b000000000000;  // SELECT analog input channel 0
    uint32_t chan_1  = 0b000100000000;  // SELECT analog input channel 1
    uint32_t chan_2  = 0b001000000000;  // SELECT analog input channel 2
    uint32_t chan_3  = 0b001100000000;  // SELECT analog input channel 3
    uint32_t chan_4  = 0b010000000000;  // SELECT analog input channel 4
    uint32_t chan_5  = 0b010100000000;  // SELECT analog input channel 5
    uint32_t chan_6  = 0b011000000000;  // SELECT analog input channel 6
    uint32_t chan_7  = 0b011100000000;  // SELECT analog input channel 7
    uint32_t chan_8  = 0b100000000000;  // SELECT analog input channel 8
    uint32_t chan_9  = 0b100100000000;  // SELECT analog input channel 9
    uint32_t chan_10 = 0b101000000000;  // SELECT analog input channel 10
    
    uint32_t test_1  = 0b101100000000;  // SELECT TEST, Voltage = (VREF+ + VREF-)/2
    uint32_t test_2  = 0b110000000000;  // SELECT TEST, Voltage = REFM
    uint32_t test_3  = 0b110100000000;  // SELECT TEST, Voltage = REFP
    
    uint32_t SW_PD   = 0b111000000000;  // SW POWERDOWN (analog + reference)
    
    uint8_t bit_8    = 0b000001000000;
    uint8_t bit_12   = 0b000000000000;
    uint8_t bit_16   = 0b000011000000;
    
    uint8_t msb      = 0b000000000000;
    uint8_t lsb      = 0b000000100000;
    
    uint8_t unipolar = 0b000000000000;
    uint8_t bipolar  = 0b000000010000;
    
    
    
    //*****************************************************************************
    //***************************************************************************//
    //These two functions translate the 24bits for each LED to something that    //
    //the WS2812b LEDs can understand. The datasheet is useless                  //                                                          //      ________                                                             //
    //          |_____ '1' is a 800ns pulse then low (can be high forever)       //
    //                                                                           //
    //             |________ '0' is a 400ns pulse (only key pulse lengt )        //
    //  the only thing that really matters is that the high pulses dont overlap  //
    //***************************************************************************//
    void Pixel_High()  // function for sending a high pulse
    {
        GPIOPinWrite(LED_PORT, LED_PIN, LED_PIN);
        SysCtlDelay(3);     //this needs to be the equv of 800ns (ish)
        GPIOPinWrite(LED_PORT, LED_PIN, 0x00);
        SysCtlDelay(3);     //length of this doesn't really matter
    }
    
    void Pixel_Low() // function for sending the low pulse
    {   // switching the pin on and off takes the proper amount of time
    	GPIOPinWrite(LED_PORT, LED_PIN, LED_PIN);
        GPIOPinWrite(LED_PORT, LED_PIN, 0x00);
        SysCtlDelay(4);     //length of this doesnt really matter
    }
    
    void clear_Ring()
    {
    	//write the same value to all the LEDs
    	int clear;
    	int count;
    	for(clear = 0; clear<NUM_LED; clear++){
    		//Green
    		for (count = 0; count < 8; count++){
    			Pixel_Low();
    		}
    		//Red
    		for (count = 0; count < 8; count++){
    			Pixel_Low();
    	    }
    		//Blue
    		for (count = 0; count < 8; count++){
    			Pixel_Low();
    		}
    	}
    }
    
    void config_LED()
    {
    	//Enable GPIO port
    	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);  // SYSCTL_PERIPH_GPIOF  * blinky *
    	while(!SysCtlPeripheralReady(SYSCTL_PERIPH_GPIOA))  // SYSCTL_PERIPH_GPIOF  * blinky *
    	{
    	}
    	GPIOPinTypeGPIOOutput(LED_PORT, LED_PIN);
    
    	//reset pixels
    	GPIOPinWrite(LED_PORT, LED_PIN, 0x00);
    	clear_Ring();
    	SysCtlDelay(10000);
    }
    
    
    //*****************************************************************************
    //***************************************************************************//...
    Read more »

  • TLV2553 - Energia

    jlbrian711/02/2016 at 14:54 0 comments

    #include <SPI.h>
    
    #include "Arduino.h"
    const int dataReadyPin = PA_5;
    const int chipSelectPin = PE_0;
    
    // TLV2553 Commands
    uint16_t chan_0  = 0b000000000000;  // SELECT analog input channel 0
    uint16_t chan_1  = 0b000100000000;  // SELECT analog input channel 1
    uint16_t chan_2  = 0b001000000000;  // SELECT analog input channel 2
    uint16_t chan_3  = 0b001100000000;  // SELECT analog input channel 3
    uint16_t chan_4  = 0b010000000000;  // SELECT analog input channel 4
    uint16_t chan_5  = 0b010100000000;  // SELECT analog input channel 5
    uint16_t chan_6  = 0b011000000000;  // SELECT analog input channel 6
    uint16_t chan_7  = 0b011100000000;  // SELECT analog input channel 7
    uint16_t chan_8  = 0b100000000000;  // SELECT analog input channel 8
    uint16_t chan_9  = 0b100100000000;  // SELECT analog input channel 9
    uint16_t chan_10 = 0b101000000000;  // SELECT analog input channel 10
    
    uint16_t test_1  = 0b101100000000;  // SELECT TEST, Voltage = (VREF+ + VREF-)/2
    uint16_t test_2  = 0b110000000000;  // SELECT TEST, Voltage = REFM
    uint16_t test_3  = 0b110100000000;  // SELECT TEST, Voltage = REFP
    
    uint16_t SW_PD   = 0b111000000000;  // SW POWERDOWN (analog + reference)
    
    uint16_t bit_8    = 0b000001000000;  // Configuration bits[3:2] {01: 8-bit output,
    uint16_t bit_12   = 0b000000000000;  //                          00: 12-bit output,
    uint16_t bit_16   = 0b000011000000;  //                          10: 12-bit output,
                                    //                          11: 16:bit output}
                                    
    uint16_t msb      = 0b000000000000;  // Configuration bits[1] {0: MSB out first,
    uint16_t lsb      = 0b000000100000;  //                        1: LSB out first}
    
    uint16_t unipolar = 0b000000000000;  // Configuration bits[0] {0: Unipolar binary,
    uint16_t bipolar  = 0b000000010000;  //                        1: Bipolar 2's complement}    
                                                                                 
    uint16_t val_null, val0, val1, val2, val3, val4, val5;
    
    SPIClass TLV2553(2);
    
    void setup()
    {
      Serial.begin(9600);
      TLV2553.begin();
      //TLV2553.setDataMode(0);
      //TLV2553.setClockDivider(128);
      
      // initialize the  data ready and chip select pins:
      pinMode(dataReadyPin, INPUT);
      pinMode(chipSelectPin, OUTPUT);
      digitalWrite(chipSelectPin, HIGH);
    }
    
    void loop()
    {
      while (!digitalRead(dataReadyPin))
      {
      }
      digitalWrite(chipSelectPin, LOW);
      val_null = TLV2553.transfer((chan_0 | bit_12 | msb | unipolar) >> 4);
      while (digitalRead(dataReadyPin)){
        val_null = (val_null << 4);
        val_null += TLV2553.transfer(0xF) >> 4;
      }
      digitalWrite(chipSelectPin, HIGH);
      
      while (!digitalRead(dataReadyPin))
      {
      }
      digitalWrite(chipSelectPin, LOW);
      val0 = TLV2553.transfer((chan_1 | bit_12 | msb | unipolar) >> 4);
      while (digitalRead(dataReadyPin)){
        val0 = (val0 << 4);
        val0 += TLV2553.transfer(0xF) >> 4;
      }
      Serial.print("A0: ");
      Serial.println(val0);
      digitalWrite(chipSelectPin, HIGH);
      
      while (!digitalRead(dataReadyPin))
      {
      }
      digitalWrite(chipSelectPin, LOW);
      val1 = TLV2553.transfer((chan_2 | bit_12 | msb | unipolar) >> 4);
      while (digitalRead(dataReadyPin)){
        val1 = (val1 << 4);
        val1 += TLV2553.transfer(0xF) >> 4;
      }
      Serial.print("A1: ");
      Serial.println(val1);
      digitalWrite(chipSelectPin, HIGH);
      
      while (!digitalRead(dataReadyPin))
      {
      }
      digitalWrite(chipSelectPin, LOW);
      val2 = TLV2553.transfer((chan_3 | bit_12 | msb | unipolar) >> 4);
      while (digitalRead(dataReadyPin)){
        val2 = (val2 << 4);
        val2 += TLV2553.transfer(0xF) >> 4;
      }
      Serial.print("A2: ");
      Serial.println(val2);
      digitalWrite(chipSelectPin, HIGH);
      
      while (!digitalRead(dataReadyPin))
      {
      }
      digitalWrite(chipSelectPin, LOW);
      val3 = TLV2553.transfer((chan_4 | bit_12 | msb | unipolar) >> 4);
      while (digitalRead(dataReadyPin)){
        val3 = (val3 << 4);
        val3 += TLV2553.transfer(0xF) >> 4;
      }
      Serial.print("A3: ");
      Serial.println(val3);
      digitalWrite(chipSelectPin, HIGH);
      
      while (!digitalRead(dataReadyPin))
      {
      }
      digitalWrite(chipSelectPin, LOW);
      val4 = TLV2553.transfer((chan_5 | bit_12 | msb | unipolar) >> 4);
      while (digitalRead(dataReadyPin)){
        val4 = (val4 << 4);
        val4 += TLV2553.transfer(0xF) >> 4;
      }
      Serial.print("A4: ");
      Serial.println(val4);
      digitalWrite(chipSelectPin, HIGH);
      
      while (!digitalRead(dataReadyPin))
      {
      }
      digitalWrite(chipSelectPin, LOW);
     val5...
    Read more »