This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Driver code for peripherals SCI, SPI etc on C2000 microcontrollers

Other Parts Discussed in Thread: CONTROLSUITE, TMS320F28377D, C2000WARE

To program peripherals SCI, SPI, I2c on Microprocessors (like f2806x and  f2802x), each peripheral TI has two sets of registers definition. For example SCI, Ti has struct _SCI_Obj_ in sci.h/sci.c and struct SCI_REGS in F2806x_Sci.h (union based from controlSUITE). They are actually same size and in same order of each member in the structure. 

So, after we use the SCI base address to do the initialization (with SCI_init()) to get SCI_Handle object. Then if we want to use SCI_REGS structure object, just cast and pass the SCI_Handle object to a pointer of SCI_REGS.

 Like the following:

 SCI_Handle  scia_handle = SCI_init((void*)SCIA_BASE_ADDR, sizeof(SCI_Obj));

SCI_REGS     *scia_regs_p = (SCI_REGS     *)scia_handle;

Just want to make sure it is the right way to do it.

Thanks.

  • Just a suggestion! I would suggest you to use the Structured approach for simplified access to SCI Register. Have a look here:
    C:\ti\controlSUITE\device_support\f2802x\v230\f2802x_examples_structs\sci_echoback

    As for your above question, I've never used driver based approach and hence no idea :)
    Surely a TIer will help you out soon.

    Regards,
    Gautam
  • I usually approach the code in this way.

    For example, if I have to use SPI

     * I create "driver_SPI.h"

    typedef volatile struct SPI_REGS* Spi;
    typedef unsigned char Uint8;
    
    // Power on peripheral
    void Spi_PowerOn(Spi spi);
    
    // Setup registers
    // as MASTER, 8 CHARS
    // no FIFO
    //
    // see "datasheet ref"
    //
    // CLKPOLARITY = ... (see page ... of datasheet)
    // CLK_PHASE   = phase of the clock (see page ... of datasheet)
    // SPIBRR      = baud rate      (see page ... of datasheet)
    void Spi_SetUp(Spi spi, int CLKPOLARITY, int CLK_PHASE, int SPIBRR);
    
    // transmit and receive a byte
    Uint8 Spi_TxRx(Spi spi, Uint8 b);

    * I develop "driver_SPI.c" (this is for TMS320F28377D)

    #include "Spi.h"
    
    void Spi_PowerOn(Spi spi)
    {
    	EALLOW; // codice per F2837xD
    	if(spi==&SpiaRegs) CpuSysRegs.PCLKCR8.bit.SPI_A = 1;
    	if(spi==&SpibRegs) CpuSysRegs.PCLKCR8.bit.SPI_B = 1;
    	if(spi==&SpicRegs) CpuSysRegs.PCLKCR8.bit.SPI_C = 1;
    	EDIS;
    }
    
    void Spi_SetUp(Spi spi, int CLKPOLARITY, int CLK_PHASE, int SPIBRR)
    {
    	//1880 di SPRUHM8C–December 2013–Revised December 2014
    
    	(*spi).SPICCR.bit.SPISWRESET 	= 0;			// Force reset
    
    	//1900 di SPRUHM8C–December 2013–Revised December 2014
    
    	(*spi).SPICCR.bit.CLKPOLARITY	= CLKPOLARITY;	//polarità clock
    	(*spi).SPICCR.bit.SPICHAR		= 7; 			//numero di caratteri (8)
    
    	//1902 di SPRUHM8C–December 2013–Revised December 2014
    
    	(*spi).SPICTL.bit.CLK_PHASE		= CLK_PHASE;	//fase clock
    	(*spi).SPICTL.bit.MASTER_SLAVE	= 1;			//master
    	(*spi).SPICTL.bit.TALK			= 1;			//TX enable (not High Z)
    
    	//1906 di SPRUHM8C–December 2013–Revised December 2014
    
    	(*spi).SPIBRR.bit.SPI_BIT_RATE	= SPIBRR;
    
    	//1880 di SPRUHM8C–December 2013–Revised December 2014
    
    	(*spi).SPICCR.bit.SPISWRESET	= 1;			// Exit reset
    
    	// wait answer from
    	// e2e.ti.com/.../404775
    	asm(" RPT #199||NOP");							// wait 1us @ 200MHz
    }
    
    Uint8 Spi_TxRx(Spi spi, Uint8 b) // trasmette/riceve un byte
    {
    	(*spi).SPITXBUF = b<<8;
    
    	//1904 di SPRUHM8C–December 2013–Revised December 2014
    
    	while((*spi).SPISTS.bit.INT_FLAG==0);
    	return((*spi).SPIRXBUF);
    }

     * And in "main.c" I use this code

    Spi_PowerOn(&SpibRegs);
    Spi_SetUp(&SpibRegs,1,0,49);// 1Mbps, 10[us/byte] (8us TX/RX, 2us DELAY)
    
    for(;;)
    {
    	Spi_TxRx(0x05);	
    }

    * But you can structure code as you like

  • You may want to check out C2000ware:
    "C2000Ware for C2000 microcontrollers is a cohesive set of development software and documentation designed to minimize software development time. From device-specific drivers and libraries to device peripheral examples, C2000Ware provides a solid foundation to begin development and evaluation. C2000Ware is an optional development tool vs. controlSUITE, though is required for the Piccolo F28004x series."

    www.ti.com/.../C2000Ware