Close

TLV2553 - CCS

A project log for Various chips

Code and stuff for various chips

jlbrian7jlbrian7 11/02/2016 at 14:560 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);
}


//*****************************************************************************
//***************************************************************************//
//  This function is called to output the data onto the LEDs         //
//      it calls the translate functions at the top              //
//***************************************************************************//
void Pixel_GRB(char position, char color)
{
	int clear;
	int count;
	switch(color){
		case 'G':
			for(clear = 0; clear<position; 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();
				}
			}
			for (count = 0; count < 8; count++){
				Pixel_High();
			}

			for (count = 0; count < 8; count++){
				Pixel_Low();
			}

			for (count = 0; count < 8; count++){
				Pixel_Low();
			}
			SysCtlDelay(1000);
			break;

		case 'R':
			for(clear = 0; clear<position; 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();
				}
			}
			for (count = 0; count < 8; count++){
				Pixel_Low();
			}

			for (count = 0; count < 8; count++){
				Pixel_High();
			}

			for (count = 0; count < 8; count++){
				Pixel_Low();
			}
			SysCtlDelay(1000);
			break;

		case 'B':
			for(clear = 0; clear<position; 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();
				}
			}
			for (count = 0; count < 8; count++){
				Pixel_High();
			}

			for (count = 0; count < 8; count++){
				Pixel_Low();
			}

			for (count = 0; count < 8; count++){
				Pixel_Low();
			}
			SysCtlDelay(1000);
			break;

		default:
			break;

	}
}
//*****************************************************************************

void setup_ssi()
{


	// put your setup code here, to run once:
	SysCtlPeripheralEnable(SYSCTL_PERIPH_SSI2);
	SysCtlDelay(3);

	// EOC is on port A, but that is enabled when the LED's are enabled
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
	while(!SysCtlPeripheralReady(SYSCTL_PERIPH_GPIOB))  //MOSI PB_7, MISO PB_6, SCK PB_4
	{
	}
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
	while(!SysCtlPeripheralReady(SYSCTL_PERIPH_GPIOE))  // TLV2553 CS PE_0
	{
	}
	GPIOPinTypeGPIOOutput(TLV2553_PORT, TLV2553_CS);
	GPIOPinWrite(TLV2553_PORT, TLV2553_CS, TLV2553_CS);

	GPIOPinTypeGPIOOutput(NRF24_PORT, NRF24_CE);
	GPIOPinTypeGPIOOutput(NRF24_PORT, NRF24_CSN);
	GPIOPinWrite(NRF24_PORT, NRF24_CE, NRF24_CE);
	GPIOPinWrite(NRF24_PORT, NRF24_CSN, NRF24_CSN);

	GPIOPinTypeGPIOInput(NRF24_PORT, TLV2553_EOC);

	GPIOPinConfigure(GPIO_PB4_SSI2CLK);
	//GPIOPinConfigure(GPIO_PB5_SSI2FSS);
	GPIOPinConfigure(GPIO_PB7_SSI2TX);
	GPIOPinConfigure(GPIO_PB6_SSI2RX);

	GPIOPinTypeSSI(GPIO_PORTB_BASE, GPIO_PIN_4);
	GPIOPinTypeSSI(GPIO_PORTB_BASE, GPIO_PIN_7);
	GPIOPinTypeSSI(GPIO_PORTB_BASE, GPIO_PIN_6);
	SSIIntClear(SSI2_BASE,SSI_TXEOT);
	//SSIDMAEnable(SSI2_BASE, SSI_DMA_RX);
	SSIConfigSetExpClk(SSI2_BASE, SysCtlClockGet(), SSI_FRF_MOTO_MODE_0, SSI_MODE_MASTER, 1000000, 12);  // 15000000  7500000
	SSIEnable(SSI2_BASE);

}

int
main(void)
{
    SysCtlDelay(10000000);
    //Set clock frequency
    ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN |
                           SYSCTL_XTAL_16MHZ);

    config_LED();
    setup_ssi();

    char pos = 0;

    while(1)
        {
    		uint32_t val_null, val0, val1, val2, val3, val4, val5;

    		while (!(GPIOPinRead(NRF24_PORT, TLV2553_EOC) & TLV2553_EOC))
    		{
    		}
    		GPIOPinWrite(TLV2553_PORT, TLV2553_CS, 0x00);
    		SSIDataPut(SSI2_BASE, (chan_0| bit_12 | msb | unipolar));  //(chan_0| bit_12 | msb | unipolar)
    		//SSIDataPut(SSI2_BASE, 0xFF);
    		while (GPIOPinRead(NRF24_PORT, TLV2553_EOC) & TLV2553_EOC)
    		{
    		}
    		GPIOPinWrite(TLV2553_PORT, TLV2553_CS, TLV2553_CS);
    		SSIDataGet(SSI2_BASE, &val_null);

    		while (!(GPIOPinRead(NRF24_PORT, TLV2553_EOC) & TLV2553_EOC))
    		{
    		}
    		GPIOPinWrite(TLV2553_PORT, TLV2553_CS, 0x00);
    		SSIDataPut(SSI2_BASE, (chan_1| bit_12 | msb | unipolar));
    		//SSIDataPut(SSI2_BASE, 0xFF);
    		while (GPIOPinRead(NRF24_PORT, TLV2553_EOC) & TLV2553_EOC)
    		{
    		}
    		GPIOPinWrite(TLV2553_PORT, TLV2553_CS, TLV2553_CS);
    		SSIDataGet(SSI2_BASE, &val0);


    		while (!(GPIOPinRead(NRF24_PORT, TLV2553_EOC) & TLV2553_EOC))
    		{
    		}
    		GPIOPinWrite(TLV2553_PORT, TLV2553_CS, 0x00);
    		SSIDataPut(SSI2_BASE, (chan_2| bit_12 | msb | unipolar));
    		//SSIDataPut(SSI2_BASE, 0xFF);
    		while (GPIOPinRead(NRF24_PORT, TLV2553_EOC) & TLV2553_EOC)
    		{
    		}
    		GPIOPinWrite(TLV2553_PORT, TLV2553_CS, TLV2553_CS);
    		SSIDataGet(SSI2_BASE, &val1);

    		while (!(GPIOPinRead(NRF24_PORT, TLV2553_EOC) & TLV2553_EOC))
    		{
    		}
    		GPIOPinWrite(TLV2553_PORT, TLV2553_CS, 0x00);
    		SSIDataPut(SSI2_BASE, (chan_3| bit_12 | msb | unipolar));
    		//SSIDataPut(SSI2_BASE, 0xFF);
    		while (GPIOPinRead(NRF24_PORT, TLV2553_EOC) & TLV2553_EOC)
    		{
    		}
    		GPIOPinWrite(TLV2553_PORT, TLV2553_CS, TLV2553_CS);
    		SSIDataGet(SSI2_BASE, &val2);

    		while (!(GPIOPinRead(NRF24_PORT, TLV2553_EOC) & TLV2553_EOC))
    		{
    		}
    		GPIOPinWrite(TLV2553_PORT, TLV2553_CS, 0x00);
    		SSIDataPut(SSI2_BASE, (chan_4| bit_12 | msb | unipolar));
    		//SSIDataPut(SSI2_BASE, 0xFF);
    		while (GPIOPinRead(NRF24_PORT, TLV2553_EOC) & TLV2553_EOC)
    		{
    		}
    		GPIOPinWrite(TLV2553_PORT, TLV2553_CS, TLV2553_CS);
    		SSIDataGet(SSI2_BASE, &val3);

    		while (!(GPIOPinRead(NRF24_PORT, TLV2553_EOC) & TLV2553_EOC))
    		{
    		}
    		GPIOPinWrite(TLV2553_PORT, TLV2553_CS, 0x00);
    		SSIDataPut(SSI2_BASE, (chan_5| bit_12 | msb | unipolar));
    		//SSIDataPut(SSI2_BASE, 0xFF);
    		while (GPIOPinRead(NRF24_PORT, TLV2553_EOC) & TLV2553_EOC)
    		{
    		}
    		GPIOPinWrite(TLV2553_PORT, TLV2553_CS, TLV2553_CS);
    		SSIDataGet(SSI2_BASE, &val4);

    		while (!(GPIOPinRead(NRF24_PORT, TLV2553_EOC) & TLV2553_EOC))
    		{
    		}
    		GPIOPinWrite(TLV2553_PORT, TLV2553_CS, 0x00);
    		SSIDataPut(SSI2_BASE, (chan_6| bit_12 | msb | unipolar));
    		//SSIDataPut(SSI2_BASE, 0xFF);
    		while (GPIOPinRead(NRF24_PORT, TLV2553_EOC) & TLV2553_EOC)
    		{
    		}
    		GPIOPinWrite(TLV2553_PORT, TLV2553_CS, TLV2553_CS);
    		SSIDataGet(SSI2_BASE, &val5);

    		//val0 = val0 << 4;
    		//SSIDataGet(SSI2_BASE, &val0);
    		//GPIOPinWrite(TLV2553_PORT, TLV2553_CS, TLV2553_CS);
    		//SysCtlDelay(10000);

    		/*val0 = 0;
    		val1 = 0;
    		val2 = 0;
    		val3 = 0;
    		val4 = 0;
    		val5 = 0;*/

            Pixel_GRB(pos, 'G');
            pos += 1;
            if (pos > 7){
            	pos = 0;
            	clear_Ring();
            }
            /*pos = position / 332;  // 153;
            if (rotatingdirection == 1){
            	Pixel_GRB(pos, 'G');
            }
            else{
            	Pixel_GRB(pos, 'R');
            }*/

        }
}

Discussions