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.

TMS320F28069MPZT uart/sci

Other Parts Discussed in Thread: TMS320F28069, MOTORWARE, CONTROLSUITE, DRV8301-69M-KIT, TMS320F28027

Im using the Piccolo TMS320F28069MPZT to dirve a motor, I also wanna make UART/SCI connection with a different chip on the same broad which does the interfacing. How to initialize the serial communication interface on TMS320F28069 chip. are there any examples i cloud use.

I do have found this line of code in the "sci.h". not sure what does parameters are

//! \param[in] pMemory     A pointer to the base address of the SCI registers
//! \param[in] numBytes    The number of bytes allocated for the SCI object, bytes
//! \return    The serial communications interface (SCI) object handle
extern SCI_Handle SCI_init(void *pMemory,const size_t numBytes);

thank you.

  • Hello,

    As I know, there is no example about this.

    But I will tell you what I did in my code to initialize SCI in Motorware (I assume you are using Motorware 12). The important thing is you should know how to call SCI APIs (from sci.h and sci.c) in hal.c (for example: you can see how PIE APIs being called there).

    1. in HAL_Handle HAL_init(void *pMemory, const size_t numBytes) {
      ...
        //Add this
        // Init SCI A registers
        obj->sciaHandle = SCI_init((void *) SCIA_BASE_ADDR, sizeof(SCI_Obj));
    ...
    } // end of HAL_init() function

    2. in void HAL_setParams(HAL_Handle handle, const USER_Params *pUserParams) {

    ...

      //Add this
        HAL_setupSCI(handle);
    ...

    }

    3. void HAL_setupGpios(HAL_Handle handle) {
       
    ...

    // Setup your GPIOs for SCI
        GPIO_setPullUp(obj->gpioHandle, GPIO_Number_28, GPIO_PullUp_Enable);
        GPIO_setPullUp(obj->gpioHandle, GPIO_Number_29, GPIO_PullUp_Enable);

        GPIO_setQualification(obj->gpioHandle, GPIO_Number_28, GPIO_Qual_ASync);

        GPIO_setMode(obj->gpioHandle, GPIO_Number_28, GPIO_28_Mode_SCIRXDA);
        GPIO_setMode(obj->gpioHandle, GPIO_Number_29, GPIO_29_Mode_SCITXDA);
    ...

    }

    4. in hal.c, add this function (that called by HAL_setParams)

    void HAL_setupSCI(HAL_Handle handle) {
        HAL_Obj *obj = (HAL_Obj *) handle;
        // Initialize all SCI registers based on your requirement. This is only example.

        // SCI stop bit, parity, loopback, char bits, idle/address mode (SCICCR = 0x07)
        SCI_setNumStopBits(obj->sciaHandle, SCI_NumStopBits_One);    // SCICCR bit 7
        SCI_setParity(obj->sciaHandle, SCI_Parity_Odd);                          // SCICCR bit 6
        SCI_disableParity(obj->sciaHandle);                                               // SCICCR bit 5
        SCI_disableLoopBack(obj->sciaHandle);                                        // SCICCR bit 4
        SCI_setMode(obj->sciaHandle, SCI_Mode_IdleLine);                     // SCICCR bit 3
        SCI_setCharLength(obj->sciaHandle, SCI_CharLength_8_Bits);   // SCICCR bit 0-2

        // TX enable, RX enable, RX ERR INT enable, SLEEP, TXWAKE (SCICTL1 = 0x03)
        SCI_disableRxErrorInt(obj->sciaHandle);                        // SCICTL1 bit 6
        SCI_disable(obj->sciaHandle);                                        // SCICTL1 bit 5
        SCI_disableTxWake(obj->sciaHandle);                           // SCICTL1 bit 3
        SCI_disableSleep(obj->sciaHandle);                              // SCICTL1 bit 2
        SCI_enableTx(obj->sciaHandle);                                    // SCICTL1 bit 1
        SCI_enableRx(obj->sciaHandle);                                    // SCICTL1 bit 0

        // TXINT enable, RXINT enable, TXEMPTY, TXRDY (SCICTL2 = 0x03)
       SCI_enableRxInt(obj->sciaHandle);                            // SCICTL2 bit 1
       SCI_disableTxInt(obj->sciaHandle);                            // SCICTL2 bit 0

        // SCIH-SCIL BAUD - SCI_BAUD = (LSPCLK/(SCI_BRR*8)) - 1
        SCI_setBaudRate(obj->sciaHandle, SCI_BaudRate_19_2_kBaud);

        // Reset SCI
        SCI_enable(obj->sciaHandle);

        PIE_enableSciInt(obj->pieHandle, SCI_RXA);                 // enable SCI interrupt
        CPU_enableInt(obj->cpuHandle, CPU_IntNumber_9);    // enable CPU interrupt
    }

    5. in pie.c, add PIE_enableSciInt()

    void PIE_enableSciInt(PIE_Handle pieHandle,const SCI_Type_e sciType)
    {
      PIE_Obj *pie = (PIE_Obj *)pieHandle;
      uint16_t index = 8;         // index is counted from 0, so INT9 has index 8
      uint16_t setValue = (1 << sciType);


      // set the value
      pie->PIEIER_PIEIFR[index].IER |= setValue;

      return;
    } // end of PIE_enableSciInt() function

    6. in hal_obj.h, add object sciaHandle and the include file

    #include "sw/drivers/sci/src/32b/f28x/f2806x/sci.h"

    typedef struct _HAL_Obj_
    {
     ...

      SCI_Handle    sciaHandle;            //!< the SCI handle (added by Maya)


    } HAL_Obj;

    These were generally what I did. If you face some error while build your SCI code based on what I wrote above (syntax or else), I believe you can fix it.

    Good luck!

    Best regards,

    Maria

  • Maria,


    How did you handle your interrupts? How are you handling the flag acknowledgement? I just found out when reading through the reference manual, to not directly clear the IFR flag. Just curious. I am using the control suite example to see how it is working. Thank you.


    Cristhian

  • Maria,

    I ended up forgoing anything to do with FIFOs and only setup to interrupt on RX. I got the code working fine now.

    Trey,

    Could you explain how the FIFO interrupts work? I've read the TRM countless times and reviewed the examples from controlSuite.

    I appreciate all the help!

    Cristhian

  • hello Maria

     in pie.c,

    void PIE_enableSciInt(PIE_Handle pieHandle,const SCI_Type_e sciType)
    {
      PIE_Obj *pie = (PIE_Obj *)pieHandle;
      uint16_t index = 8;         // index is counted from 0, so INT9 has index 8
      uint16_t setValue = (1 << sciType);


      // set the value
      pie->PIEIER_PIEIFR[index].IER |= setValue;

      return;
    } // end of PIE_enableSciInt() function

    SCI_Type_e  is not difined in pie.h .

    So can you show how you defined it ?

    am I right define it like this:

  • Hello,

    I defined it in sci.h, not in pie.h, like below:

    typedef enum
    {
      SCI_RXA=0,              //!< Denotes SCI receive A
      SCI_TXA=1,                 //!< Denotes SCI transmit A
      SCI_RXB=2,                //!< Denotes SCI receive B
      SCI_TXB=3               //!< Denotes SCI transmit B
    } SCI_Type_e;



    Best regards,

    Maria

  • Hi Maria,

    I modified the code in  proj_lab13e  , and the MCU can send characters to my PC . But when my PC send a character to MCU , there is no response. And this is my code:

    //in hal.c
    HAL_Handle HAL_init(void *pMemory,const size_t numBytes)
    {
      //add :
      // initialize the SCIA handle
      obj->sciAHandle=SCI_init((void*)SCIA_BASE_ADDR,sizeof(SCI_Obj));
    }
    
    void HAL_setParams(HAL_Handle handle,const USER_Params *pUserParams)
    {
      //add:
      // setup the sciA
      HAL_setupSciA(handle);
    }
    
    //add fuction
    void HAL_setupSciA(HAL_Handle handle)
    {
      HAL_Obj   *obj = (HAL_Obj *)handle;
    
    //  SCI_reset(obj->sciAHandle);
      SCI_setMode(obj->sciAHandle,SCI_Mode_IdleLine);            
      SCI_setCharLength(obj->sciAHandle,SCI_CharLength_8_Bits);  
      SCI_setNumStopBits(obj->sciAHandle,SCI_NumStopBits_One);   
      SCI_setParity(obj->sciAHandle, SCI_Parity_Odd);
      SCI_disableParity(obj->sciAHandle);                        
      SCI_disableLoopBack(obj->sciAHandle);                      
    
      SCI_disableRxErrorInt(obj->sciAHandle);                    
      SCI_disable(obj->sciAHandle);
      SCI_disableTxWake(obj->sciAHandle);                        
      SCI_disableSleep(obj->sciAHandle);                         
      SCI_enableTx(obj->sciAHandle);                             
      SCI_enableRx(obj->sciAHandle);                             
    
      SCI_setBaudRate(obj->sciAHandle,SCI_BaudRate_115_2_kBaud); //  LSPCLK =(90M/4), BAUD = LSPCLK/((BRR+1) *8)
      SCI_clearRxFifoInt(obj->sciAHandle);                       
      SCI_enableRxInt(obj->sciAHandle);                          
      SCI_disableTxInt(obj->sciAHandle);                         
      SCI_enable(obj->sciAHandle);
    
      PIE_enableSciInt(obj->pieHandle, SCI_RXA);                 // enable SCI interrupt
      CPU_enableInt(obj->cpuHandle, CPU_IntNumber_9);            // enable CPU interrupt
    
      return;
    }
    
    void HAL_setupGpios(HAL_Handle handle)
    {
      //add:
     // SCI RX A
      GPIO_setMode(obj->gpioHandle,GPIO_Number_28,GPIO_28_Mode_SCIRXDA);
    
      // SCI TX A
      GPIO_setMode(obj->gpioHandle,GPIO_Number_29,GPIO_29_Mode_SCITXDA);
    }
    
    
    //in hal_obj.h
    typedef struct _HAL_Obj_
    {
      //add:
      SCI_Handle    sciAHandle ;
      SCI_Obj       sciA;
    }
    
    
    //in pie.c 
    //add fuction 
    void PIE_enableSciInt(PIE_Handle pieHandle,const SCI_IntNumber_e sciType)
    {
      PIE_Obj *pie = (PIE_Obj *)pieHandle;
      uint16_t index = 8;         // index is counted from 0, so INT9 has index 8
      uint16_t setValue = (1 << sciType);
    
    
      // set the value
      pie->PIEIER_PIEIFR[index].IER |= setValue;
    
      return;
    }
    
    
    //in sci.h 
    //add:
    typedef enum
    {
      SCI_RXA=0,   //!< Denotes SCIRXINTA
      SCI_TXA,     //!< Denotes SCITXINTA
      SCI_RXB,     //!< Denotes SCIRXINTB
      SCI_TXB      //!< Denotes SCITXINTB
    } SCI_IntNumber_e;
    
    //in sci.c
    //add fuction
    void SCI_send_char(SCI_Handle sciHandle,char a)
    {
    	SCI_Obj *sci = (SCI_Obj *)sciHandle;
    
        while(SCI_getTxFifoStatus(sci) != SCI_FifoStatus_Empty){
        }
        SCI_write(sci, a);
    }
    
    //in pro_lab13e.c 
    //add interrupt fuction
    interrupt void SCI_RX_ISR(void)
    {
      char rev_data = 0 ;
      if(SCI_rxDataReady(halHandle->sciAHandle)==1)
      {
        rev_data = SCI_read(halHandle->sciAHandle);
        SCI_send_char(halHandle->sciAHandle,char rev_data);
      }
      SCI_clearRxFifoOvf(halHandle->sciAHandle); 
      SCI_clearRxFifoInt(halHandle->sciAHandle); 
    }
    
    
    //in hal.h
    static inline void HAL_initIntVectorTable(HAL_Handle handle)
    {
      //add:
      pie->SCIRXINTA = &SCI_RX_ISR;
    }
    
    

     

  • Hello Stefan,

    Which version of Motorware that you use?

    I am not sure which one is missing.

    But I notice that there is no PIE ACK for your interrupt in your ISR.

    I made my own HAL_pieAckInt() in hal.c and call it in my SCI ISR.

    HAL_pieAckInt(halHandle,PIE_GroupNumber_9);        // Issue PIE ack INT9

    And also in HAL_setupGpios(), you need to set:

    GPIO_setPullUp(obj->gpioHandle, GPIO_Number_28, GPIO_PullUp_Enable);
    GPIO_setPullUp(obj->gpioHandle, GPIO_Number_29, GPIO_PullUp_Enable);

    GPIO_setQualification(obj->gpioHandle, GPIO_Number_28, GPIO_Qual_ASync);

    GPIO_setMode(obj->gpioHandle, GPIO_Number_28, GPIO_28_Mode_SCIRXDA);
    GPIO_setMode(obj->gpioHandle, GPIO_Number_29, GPIO_29_Mode_SCITXDA);

    Let me know whether this helps you or not.

    Best regards,

    Maria

  • Instead of adding

      void PIE_enableSciInt(PIE_Handle pieHandle,const SCI_Type_e sciType)

    and the enums, you can just do this:

    PIE_enableInt(obj->pieHandle, PIE_GroupNumber_9, PIE_InterruptSource_SCIARX);

  • Hi Folks,

    I'm a bit rusty as it's been a few years since I've gotten my hands dirty with C++ so please be gentle.

    I've added the code Maria suggested but I get the following error:

    error #20: identifier "SCI_Type_e" is undefined

    In the sci.h file I define SCI_Type_e as:

    typedef enum
    {
    SCI_RXA=0, //!< Denotes SCI receive A
    SCI_TXA=1, //!< Denotes SCI transmit A
    SCI_RXB=2, //!< Denotes SCI receive B
    SCI_TXB=3 //!< Denotes SCI transmit B
    } SCI_Type_e;

    So, can you point out what I might've done wrong? I have a #include "sci.h" in the sci.c file.
    Thanks,

    Richard C
  • Richard,

    You don't need that enum at all.  See my post right above you.

    You can replace that enum and Maria's PIE_enableSciInt() function with

      // enable SCI interrupt
      PIE_enableInt(obj->pieHandle, PIE_GroupNumber_9, PIE_InterruptSource_SCIARX);

    Like this (I modified the baud argument for my application):

    void HAL_setupSCI(HAL_Handle handle) {
      HAL_Obj *obj = (HAL_Obj *) handle;
      // Initialize all SCI registers based on your requirement. This is only example.
    
      // SCI stop bit, parity, loopback, char bits, idle/address mode
      SCI_setNumStopBits(obj->sciAHandle, SCI_NumStopBits_One);
      //SCI_setParity(obj->sciAHandle, SCI_Parity_Odd);
      SCI_disableParity(obj->sciAHandle);
      SCI_disableLoopBack(obj->sciAHandle);
      SCI_setMode(obj->sciAHandle, SCI_Mode_IdleLine);
      SCI_setCharLength(obj->sciAHandle, SCI_CharLength_8_Bits);
    
      // TX enable, RX enable, RX ERR INT enable, SLEEP, TXWAKE (SCICTL1 = 0x03)
      SCI_disableRxErrorInt(obj->sciAHandle);
      SCI_disable(obj->sciAHandle);
      SCI_disableTxWake(obj->sciAHandle);
      SCI_disableSleep(obj->sciAHandle);
      SCI_enableTx(obj->sciAHandle);
      SCI_enableRx(obj->sciAHandle);
      SCI_enableTxFifo(obj->sciAHandle);
      SCI_enableTxFifoEnh(obj->sciAHandle);
    
      // TXINT enable, RXINT enable, TXEMPTY, TXRDY (SCICTL2 = 0x03)
      SCI_enableRxInt(obj->sciAHandle);
      SCI_disableTxInt(obj->sciAHandle);
    
      // SCIH-SCIL BAUD - SCI_BAUD = (LSPCLK/(SCI_BRR*8)) - 1
      SCI_setBaudRate(obj->sciAHandle, 9374 /*SCI_BaudRate_19_2_kBaud*/);
    
      // Reset SCI
      SCI_enable(obj->sciAHandle);
    
      // enable SCI interrupt
      PIE_enableInt(obj->pieHandle, PIE_GroupNumber_9, PIE_InterruptSource_SCIARX);
    
      // enable CPU interrupt
      CPU_enableInt(obj->cpuHandle, CPU_IntNumber_9);
    }

  • Rick,

    Thanks.  It looks like it will work.  I can get it to compile without any errors but since I won't have the hardware until next week I won't know for sure if it works.  But you've certainly helped me. 


    I noticed in one of the earlier posts by Maria she commented that a PIE ACK needs to be generated in the ISR.  Does your code do that you do you somehow get around that?


    Thanks again,

    Richard C

  • I'm doing something like this for test (loopback)

    // SCI Receive Data ISR
    interrupt void SCI_RX_ISR(void)
    {
      char rxdata = 0 ;
      if(SCI_rxDataReady(halHandle->sciAHandle)==1)
      {
        rxdata = SCI_read(halHandle->sciAHandle);
        SCI_write_char(halHandle->sciAHandle, rxdata);
      }
      SCI_clearRxFifoOvf(halHandle->sciAHandle);
      SCI_clearRxFifoInt(halHandle->sciAHandle);
      PIE_clearInt(halHandle->pieHandle, PIE_GroupNumber_9);
    }
    

  • Rick,

    Thanks for the help but I have another question so I hope you don't mind. I'm pretty comfortable in C but not as much for C++ so I'm still trying to understand the TI code. How are you handling the RX and TX in your code? I just need to be able to read and write a few chars in my main loop but I'm stuck.

    In SCI.C there are:

    void SCI_putDataBlocking(SCI_Handle sciHandle, uint16_t data)
    and
    uint16_t SCI_putDataNonBlocking(SCI_Handle sciHandle, uint16_t data)

    Which one do you use? Do you happen to know where they might be described?

    Thanks,

    Richard C
  • This code is C, not C++, so I don't think that has anything to do with understanding the code...  This is pretty standard C for dealing with memory-mapped peripherals:  A struct is used to represent the registers and a pointer to that struct type is set to the base address of the memory-mapped peripheral.  Despite the marketing claims for InstaSPIN, I have yet to see any object-oriented code in the labs (no vtables, no inheritance, no abstraction or design patterns, etc.).  The usage of structs as a kind of a "this" pointer as the first argument to each function is the beginnings of how one would implement OO in C, but that alone doesn't make this object-oriented.

    Hmmm...  I recompiled my test code and the receive side quit working.  The data ready status bit (which fires the interrupt) appears to have quit working after I made changes to enable the transmit FIFO.  After hacking at it a while, here's what I have for you:

    This turns on both the transmit and receive FIFOs and sets the receive FIFO to interrupt on the first byte.  The handler then empties the FIFO in a loop.  SCI_write_char() is the heart of the transmit side -- it waits for the transmit FIFO to have at least one byte free before using SCI_write() to send the next character.


    This is far from production-ready but should be enough to get you started with buffered communications on the SCI.

    void HAL_setupSCI(HAL_Handle handle) {
      HAL_Obj *obj = (HAL_Obj *) handle;
      // Initialize all SCI registers based on your requirement. This is only example.
    
      // SCI stop bit, parity, loopback, char bits, idle/address mode
      SCI_setNumStopBits(obj->sciAHandle, SCI_NumStopBits_One);
      //SCI_setParity(obj->sciAHandle, SCI_Parity_Odd);
      SCI_disableParity(obj->sciAHandle);
      SCI_disableLoopBack(obj->sciAHandle);
      SCI_setMode(obj->sciAHandle, SCI_Mode_IdleLine);
      SCI_setCharLength(obj->sciAHandle, SCI_CharLength_8_Bits);
    
      // TX enable, RX enable, RX ERR INT enable, SLEEP, TXWAKE (SCICTL1 = 0x03)
      SCI_disableRxErrorInt(obj->sciAHandle);
      SCI_disable(obj->sciAHandle);
      SCI_disableTxWake(obj->sciAHandle);
      SCI_disableSleep(obj->sciAHandle);
      SCI_enableTx(obj->sciAHandle);
      SCI_enableRx(obj->sciAHandle);
      SCI_enableTxFifo(obj->sciAHandle);
      SCI_enableTxFifoEnh(obj->sciAHandle);
    
      // TXINT enable, RXINT enable, TXEMPTY, TXRDY (SCICTL2 = 0x03)
      //SCI_enableRxInt(obj->sciAHandle);
      SCI_enableRxFifoInt(obj->sciAHandle);
      SCI_setRxFifoIntLevel(obj->sciAHandle, SCI_FifoLevel_1_Word);
      SCI_disableTxInt(obj->sciAHandle);
    
      // SCIH-SCIL BAUD - SCI_BAUD = (LSPCLK/(SCI_BRR*8)) - 1
      SCI_setBaudRate(obj->sciAHandle, 9374 /*SCI_BaudRate_19_2_kBaud*/);
    
      // Reset SCI
      SCI_enable(obj->sciAHandle);
    
      // enable SCI interrupt
      PIE_enableInt(obj->pieHandle, PIE_GroupNumber_9, PIE_InterruptSource_SCIARX);
    
      // enable CPU interrupt
      CPU_enableInt(obj->cpuHandle, CPU_IntNumber_9);
    }
    
    void SCI_write_char(SCI_Handle sciHandle,char a)
    {
        SCI_Obj *sci = (SCI_Obj *)sciHandle;
    
        while(SCI_getTxFifoStatus(sci) == SCI_FifoStatus_4_Words) { }
        SCI_write(sci, a);
    }
    
    void SCI_write_str(SCI_Handle sciHandle, char* str)
    {
    	while(*str != 0)
    	{
    		SCI_write_char(sciHandle, *str++);
    	}
    }
    
    // SCI Receive Data ISR
    interrupt void SCI_RX_ISR(void)
    {
      char rxdata = 0 ;
      while(SCI_FifoStatus_Empty != SCI_getRxFifoStatus(halHandle->sciAHandle))
      {
        rxdata = SCI_read(halHandle->sciAHandle);
        SCI_write_char(halHandle->sciAHandle, rxdata);
      }
      SCI_clearRxFifoOvf(halHandle->sciAHandle);
      SCI_clearRxFifoInt(halHandle->sciAHandle);
      PIE_clearInt(halHandle->pieHandle, PIE_GroupNumber_9);
    }

     

  • Hi Rick,


    Thanks a million for your help.  I don't want to be a pain but I'm getting an error:

    error #20: identifier "halHandle" is undefined

    For the line:

    while(SCI_FifoStatus_Empty != SCI_getRxFifoStatus(halHandle->sciAHandle))  This is line# 62 of your example code.

    Should it be (obj->sciAHandle)?  Or am I leaving something out?


    Thanks again,

    Richard C

  • Rick,

    My mistake. I now realize that SCI_write_char() and SCI_write_str() functions belong in SCI.C and the SCI_RX_ISR() function belongs in the main project.c file. Sorry for my earlier message.

    Thanks again for your help. I'm still not out of the woods but I think I'm making progress.

    Richard C
  • Rick,

    I've looked high and low to try and fin out what I've done wrong but my head hurts from banging it against the wall.

    I get 5 of these errors:

    #137 struct "_HAL_Obj_" has no field "sciAHandle"

    It's this code in my main.c code:

    // SCI Receive Data ISR
    interrupt void SCI_RX_ISR(void)
    {
         char rxdata = 0 ;
         while(SCI_FifoStatus_Empty != SCI_getRxFifoStatus(halHandle->sciAHandle))
         {
           rxdata = SCI_read(halHandle->sciAHandle);
           SCI_write_char(halHandle->sciAHandle, rxdata);
         }
         SCI_clearRxFifoOvf(halHandle->sciAHandle);
         SCI_clearRxFifoInt(halHandle->sciAHandle);
         PIE_clearInt(halHandle->pieHandle, PIE_GroupNumber_9);
    }

    Can you tell what I did wrong?

    Thanks,

    Richard C

  • Look again in hal_obj.h -- this is something you have to manually add and there's a case difference between my code and Maria's original post. Maria named it sciaHandle and I named it sciAHandle to be consistent with the other handles in the struct (spiAHandle and spiBHandle). You can just rename it with a lower-case "a" and it should compile, or go rogue like I did and rename it everywhere else with an upper-case "A" :)

    I put my write_char and write_str functions in the main project.c file, actually. You need to either add forward declarations (function prototype) for them somewhere or make sure they're pasted before/above any code that uses them like main() or SCI_RX_ISR().
  • Rick,

    It bugged me too that Maria didn't define the SCI handle the same as TI did the SPI so I made it the same like you did:

    SCI_Handle    sciAHandle;       //!< the SCI handle (added by RC_edit 5/14/15)
    SCI_Obj           sciA;	               //!< the SCIA object

    And I put the function prototypes for your two new functions in SCI.H.

    What's really wierd is in the void HAL_setupSCI(HAL_Handle handle) function none of the enclosed functions are displayed

    bold like they are in the Hal_setupSPI( ) function. It's almost like the compiler is ignoring them. I don't know if this forum system will show

    it but here is the code:

    
    
    void HAL_setupSpiA(HAL_Handle handle)
    {
      HAL_Obj   *obj = (HAL_Obj *)handle;
    
      SPI_reset(obj->spiAHandle);
      SPI_setMode(obj->spiAHandle,SPI_Mode_Master);
      SPI_setClkPolarity(obj->spiAHandle,SPI_ClkPolarity_OutputRisingEdge_InputFallingEdge);
      SPI_enableTx(obj->spiAHandle);
      SPI_enableTxFifoEnh(obj->spiAHandle);
      SPI_enableTxFifo(obj->spiAHandle);
      SPI_setTxDelay(obj->spiAHandle,0x0010);
      SPI_setBaudRate(obj->spiAHandle,(SPI_BaudRate_e)(0x000d));
      SPI_setCharLength(obj->spiAHandle,SPI_CharLength_16_Bits);
      SPI_setSuspend(obj->spiAHandle,SPI_TxSuspend_free);
      SPI_enable(obj->spiAHandle);
    
      return;
    }  // end of HAL_setupSpiA() function
    
    
    void HAL_setupSCI(HAL_Handle handle)
    {
        HAL_Obj  *obj = (HAL_Obj *)handle;
        // Initialize all SCI registers based on your requirement. This is only example.
    
        // SCI stop bit, parity, loopback, char bits, idle/address mode
        SCI_setNumStopBits(obj->sciAHandle, SCI_NumStopBits_One);
        //SCI_setParity(obj->sciAHandle, SCI_Parity_Odd);
        SCI_disableParity(obj->sciAHandle);
        SCI_disableLoopBack(obj->sciAHandle);
        SCI_setMode(obj->sciAHandle, SCI_Mode_IdleLine);
        SCI_setCharLength(obj->sciAHandle, SCI_CharLength_8_Bits);
    
        // TX enable, RX enable, RX ERR INT enable, SLEEP, TXWAKE (SCICTL1 = 0x03)
        SCI_disableRxErrorInt(obj->sciAHandle);
        SCI_disable(obj->sciAHandle);
        SCI_disableTxWake(obj->sciAHandle);
        SCI_disableSleep(obj->sciAHandle);
        SCI_enableTx(obj->sciAHandle);
        SCI_enableRx(obj->sciAHandle);
        SCI_enableTxFifo(obj->sciAHandle);
        SCI_enableTxFifoEnh(obj->sciAHandle);
    
        // TXINT enable, RXINT enable, TXEMPTY, TXRDY (SCICTL2 = 0x03)
        SCI_enableRxInt(obj->sciAHandle);
        SCI_disableTxInt(obj->sciAHandle);
    
        // SCIH-SCIL BAUD - SCI_BAUD = (LSPCLK/(SCI_BRR*8)) - 1
        SCI_setBaudRate(obj->sciAHandle, SCI_BaudRate_19_2_kBaud);
    
        // Reset SCI
        SCI_enable(obj->sciAHandle);
    
        // enable SCI interrupt
        PIE_enableInt(obj->pieHandle, PIE_GroupNumber_9, PIE_InterruptSource_SCIARX);
    
        // enable CPU interrupt
        CPU_enableInt(obj->cpuHandle, CPU_IntNumber_9);
    
        return;
    }	// end of HAL_setupSCI() function
    
    

    Thanks,

    Richard C

  • Another minor point is that I don't think you need to add

    SCI_Obj           sciA;	               //!< the SCIA object

    to _HAL_Obj_.  It's neither used nor set anywhere and I left it out of mine.  

    Do you have it working now or are you still having problems? 

    Be aware, by the way, that those baud rate enums are probably incorrect for you application.  From their definition:

    //! \brief Enumeration to define the serial communications interface (SCI) baud rates.  This enumeration assume a device clock of 60Mhz and a LSPCLK of 15MHz
    //!
    typedef enum
    {
      SCI_BaudRate_9_6_kBaud = 194,      //!< Denotes 9.6 kBaud
      SCI_BaudRate_19_2_kBaud = 97,      //!< Denotes 19.2 kBaud
      SCI_BaudRate_57_6_kBaud = 33,      //!< Denotes 57.6 kBaud
      SCI_BaudRate_115_2_kBaud = 15      //!< Denotes 115.2 kBaud
    } SCI_BaudRate_e;

    It's assuming an LSPCLK of 15MHz whereas the lab demos for the DRV8301-69M-KIT, for example, run it at 90MHz.

    Use this formula to calculate the correct value and just override the poorly thought-out enum:

    SCI BRR = ( LSPCLK/(BAUDx8) ) - 1

    So if you're using 90MHz like the demo board and examples, you would use a value of 585 for the BRR to set it to 19200.

    90000000/(19200*8) - 1 = 584.9375.

    Flipping it around, the actual baud rate would be 90000000/((585+1)*8) = 19198.  Pretty darn close!

    The lack of syntax hilighting doesn't necessarily mean that the compiler is ignoring it.  What the IDE does and what the compiler do are different.  Try rebuilding the project instead of building (or clean and then build) and make sure you don't have any errors.  Did you add #include "sw/drivers/sci/src/32b/f28x/f2806x/sci.h" towards to the top of hal_obj.h?

  • Rick,

    I'm ready to throw my computer out the window. I'm still getting the 5 errors:

    error #137: struct "_HAL_Obj_" has no field "sciAHandle"

    In the interrupt void SCI_RX_ISR(void) function in my main.c code. I've checked that I have the proper definition in the Hal_obj.h file:
    SCI_Handle sciAHandle; //!< the SCI handle (added by RC_edit 5/14/15)

    I have your code to setup the SCI in HAL.C. I just don't know what else to try. It sure looks like it's correct but I keep getting those 5 errors. I've done a clean and then build but that didn't help.

    Thanks,

    Richard C
  • Hmm It's entirely possible that you've added it to a hal_obj.h that lives in a different directory than the one your project is pulling in. To make sure you're opening the correct hal_obj.h, try this:
    In your project.c file, up towards the top, find the line that reads:
    HAL_Handle halHandle;
    and left-click to place the cursor on HAL_Handle. Then press F3 (or right-click and select "Open Declaration"). That should open up the hal_obj.h file that is associated with your project.

    Double-check that the edits are made to that file. Scrutinize their location and case.
  • I think that was the problem. Now I have to figure out why it was using the original file and not the edited version in the new location.

    Thanks for the F3 tip. I never would have thought of that to find the problem.
  • I finally got it to compile with no errors and I owe it all to you. I just had to add the proper location into the "Include Options" in the project properties. Once I did that it compiled just fine. Now I can go to bed and not worry about this issue. I'm sure something will happen tomorrow but for now it's all good. Thanks again.
  • In the project explorer (view->Project Explorer if it's not already open) right-click your project file and open the properties. Over on the left open Build->C2000 Compiler and Include Options. You'll see your include paths and probably the first one is "${MW_INSTALL_DIR}/sw/modules/hal/boards/drv8301kit_revD/f28x/f2806x/src/" which is where hal_obj.h lives. That one will get picked up before any of your overrides because it's in the first path.

    Edit:  I see that you found that out while I was posting my reply :)   Sleep tight!

  • I'm using the 28027F Launchpad so I think the LSPCLK on this board runs at 15MHz (60MHz/4) so the LAB values for the baud rate should be accurate.  At least I hope so.

  • Both of your discussion was super helpful for me. I have followed what you did for the code but I get an error #29: Expected and Expression where I am using the write function. Can you help me with that? I am doing exactly what you are doing as a starting point but I am stuck here. I tried searching the forum for that particular error but could not find anything useful. 

  • Nevermind. It was a silly mistake. I had copied the function from where it was defined so I copied 'char' instead of just putting in the actual data. It is compiling now :-)
  • Hi, i am enabling serial communication in TMS320F28027. i added the above code in my project. now i want to transmit data out. i try the below 3 functions. when i uses these functions i am getting errors like undefined sci, undefined sciHandle. what is the correct function format to transmit data. and what i have to declare to remove those errors. i am calling this function in Project10a.c in forever loop.

    SCI_write(sci, 0X55);

    SCI_write(obj->sciHandle, 0X55);

    SCI_write(Handle, 0X55);

  • Have you  added the functions in hal.c? Then you might have syntax error. If you  are following the recomended practice of adding everything in hal.c and then calling the functions in main.c your program should look like this;

    in hal.c

    ......

    void HAL_sciaWrite(HAL_Handle handle, const uint16_t data)
    {
    HAL_Obj *obj = (HAL_Obj *) handle;

    SCI_write(obj->sciaHandle, data);
    }

    ....

    And in main.c call the following function;

    ...

    HAL_sciaWrite(halHandle, 0x5555);

    ...

    What that basically does is it calls the function from sci.h through hal.c. Make sure you are using the same handles (sciHandle vs. sciaHandle etc.) Make sure you have defined the sci handle where all the other handles are defined in hal.c in the same way. 

    // Init SCI A registers
    obj->sciaHandle = SCI_init((void *) SCIA_BASE_ADDR, sizeof(SCI_Obj));

  • Hi,

    I have followed the above codes in my project including the code from Stefan, which modified from project 10a. The compilation is now perfect However, I don't know how to test the code. I use putty in the test and I have com3 and 4 found in the Device Manager.

    So, should I use Com 3 in Putty? and what is the baud rate in the test, is it 19200? In my case, I have seen the Chinese characters come out when I hit some keys on keyboards.

    Best regards,
    Shawn
  • I was using a demo board and I just connected the MODBUS of the processor to my PC via Serial-USB converter and used a free software called Windmill to check the response. I suggest you create a new thread to get specific answers. This one is pretty old.
  • Shawn,


    For testing, I've used the program Terminal, but the setup should be similar to PuTTy. When you plug your Launchpad/ControlCARD in to your computer, which COM number is assigned to your device? You can find out by looking in Windows Device Manager under Ports. That's the COM port you should be connecting to from your terminal program.


    Also, you'll need to ensure you have the correct SCI module (A or B) mapped to the FTDI/USB/UART connections. For instance, if you have SCI-A mapped to GPIO28/29, you'll need to make sure GPIO28/29 are selected for UART. Which development kit are you using for testing? ControlCARD uses SCI-A as the default module for UART/USB comms to a terminal


    Finally, ensure you have the correct Baud rate set. Don't use the predefined Baud rate enum types. Instead calculate the rate using:

    Baud Rate Register = (LSPCLK/(desired rate * 8)) - 1


    If you want a Baud rate = 9600, it would look something like:

    BRR = (LSPCLK/(9600*8)) – 1 ~= 117110 = 49316

    where LSPCLK = 90MHz in my case

    Sean