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.

Failure: SPI-Communication

Other Parts Discussed in Thread: DRV8301, BOOSTXL-DRV8301, MOTORWARE, CONTROLSUITE

I have Problems with my SPI-communication. When i am debug my program, what is based on Lab12b, i get the following error.

C28xx: Trouble Writing Memory Block at 0xbac1 on Page 0 of Length 0x1: (Error -1142 @ 0xBAC2) Device blocked debug access because it is currently executing non-debuggable code. Choose 'Rude Retry' to disable polite mode and force the operation. (Emulation package 5.1.507.0)

When i am comment my SPI-function the programm works without any error. The Master is the MCU and the Slave is a FPGA. First i want to read one single Register (1 Byte) from the FPGA with a function. 

Here are my SPI functions:

/* Send one byte and get one back */
void HAL_SPI_TransReceive(HAL_Handle handle, uint8_t *transdata, uint8_t *receivedata)		//-----
{
HAL_Obj *obj = (HAL_Obj *)handle;
SPI_Obj *spiA = (SPI_Obj *)obj->spiAHandle;
SPI_write(spiA,*transdata);
while(1)			//Warten bis Übertragung abgeschlossen
{
	if(SPI_getIntFlagStatus(spiA)==SPI_IntFlagStatus_Completed)
		{
			*receivedata=(uint_least8_t) SPI_read(spiA);
			break;
		}
}
return;
}


/*read a register*/
void ReadSingleReg(HAL_Handle handle, uint8_t reg_addr, uint8_t *receivedata)
{
	HAL_Obj *obj = (HAL_Obj *)handle;
	SPI_Obj *spiA = (SPI_Obj *)obj->spiAHandle;
	uint_least16_t onlinestatus=0x0000;

	reg_addr=((0x80)||(reg_addr));

	spiA->SPICTL|=0x02; // Chip Select Setzen

	HAL_SPI_TransReceive(handle,&reg_addr,receivedata);
	onlinestatus=(uint_least16_t)*receivedata;
	onlinestatus=onlinestatus<<(7);
	reg_addr=0x3F;
	HAL_SPI_TransReceive(handle,&reg_addr,receivedata);
	onlinestatus=(uint_least16_t)*receivedata;
	HAL_SPI_TransReceive(handle,&reg_addr,receivedata);


	spiA->SPICTL&=0xFD; // Chip Select Rücksetzen
	return;
}

my SPI configuration is:

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_setClkPhase(obj->spiAHandle,SPI_ClkPhase_Normal);
  SPI_enableTx(obj->spiAHandle);
  SPI_enableTxFifoEnh(obj->spiAHandle);
  SPI_enableTxFifo(obj->spiAHandle);
  SPI_setTxDelay(obj->spiAHandle,0x0018);
  SPI_setBaudRate(obj->spiAHandle,(SPI_BaudRate_e)(0x0003));
  SPI_setCharLength(obj->spiAHandle,SPI_CharLength_8_Bits);
  SPI_setSuspend(obj->spiAHandle,SPI_TxSuspend_free);
  SPI_enable(obj->spiAHandle);

  return;
}

 
What is the reason of my failure? I hope somebody could help me.

I am calling the function in the MainISR:

ReadSingleReg(halHandle, version, &SPI_Receivedata);

 

  • Another Question. For what is the DRV8301_SPI? Is the the Communication line between mcu und motorcontroller? Has this SPI port something to do with the SPI-Channel A of the MCU or is this another SPI-Port? Thanks you for answer.

  • Hello,

    I'm not really familiar with this error, but when I search the forum, I see people tying it to enabling realtime mode in your debugging options. Try reading through this thread:

    http://e2e.ti.com/support/microcontrollers/c2000/f/171/t/331684.aspx

    When is this error occurring? Have you been able to place breakpoints to try to get a better idea of what function in particular is failing or are you unable to run at all?

    Thanks,

    Whitney

  • Christian Dold said:
    For what is the DRV8301_SPI?

    Yes, when using the DRV8301 chip you must configure it with a SPI port from the MCU.

    Christian Dold said:
    Has this SPI port something to do with the SPI-Channel A of the MCU or is this another SPI-Port?

    We we are using SPI-A for this communication interface on BOOSTXL-DRV8301 but SPI-B for this communication interface with DRV8301 EVM Rev D.

    you can find this in the hal.c file

    DRV8301_setSpiHandle

  • Hi Whitney,

    Hi Chris,

    thanks for answer! I have solved my Problem. I am using a type uint8_t and i am thinking that type has a size of 8 Bit but it has a size of 16bit. So i overwrite memoryspace i have not reserved before. I am changing the typdef 

    from

    typedef uint16_t uint_least8_t;

    typedef  int16_t  int_least8_t;

    to 

    typedef unsigned char int8_t;

    typedef  int8_t uint8_t;

    I have another question to Chris answer. I am using DRV8301-HC-C2-EVM Board with a BLDC-Motor and Lab12b. Could i using the SPIA-Interface for communication with my FPGA? Does the SPI-B communication to the DRV8301 also work when i change the configuration of GPIO 24-26 as QEP2 to add a second Encoder to the System?

    Have you a solution to use one SPI to communicat with the FPGA and add a second Encoder, with A, B, I signals, to the System. Is this possible with this kind of system?

    Sorry for this dumb questions but i am not common with this kind of Motorcontroller.

    Thank you for help  

     

  • Christian Dold said:
    Could i using the SPIA-Interface for communication with my FPGA? Does the SPI-B communication to the DRV8301 also work when i change the configuration of GPIO 24-26 as QEP2 to add a second Encoder to the System?

    you need to check the mapping in HAL and on the hardware

    HW: header J5 is the isolated SPI connection, and these pins are routed to the DIMM connector pins: 38, 39, 88, 89

    which correspond to the F28069 GPIO pins: 16, 18, 17, 19

    SW: from the HAL files C:\ti\motorware\motorware_1_01_00_13\sw\modules\hal\boards\drv8301kit_revD\f28x\f2806x\src

    by default they are set to:

      // SPI-SIMO
      GPIO_setMode(obj->gpioHandle,GPIO_Number_16,GPIO_16_Mode_GeneralPurpose);

      // SPI-SOMI
      GPIO_setMode(obj->gpioHandle,GPIO_Number_17,GPIO_17_Mode_GeneralPurpose);

      // SPI-CLK
      GPIO_setMode(obj->gpioHandle,GPIO_Number_18,GPIO_18_Mode_GeneralPurpose);

      // SPI-STE
      GPIO_setMode(obj->gpioHandle,GPIO_Number_19,GPIO_19_Mode_GeneralPurpose);

    which you will need to update to setting them as SPI pins by using:

    GPIO_16_Mode_SPISIMOA

    GPIO_17_Mode_SPISOMIA

    GPIO_18_Mode_SPICLKA

    GPIO_19_Mode_SPISTEA_NOT

    but you also need to go through the process of initializing SPIA, like is done for SPIB

    // initialize the SPIA handle
      obj->spiAHandle = SPI_init((void *)SPIA_BASE_ADDR,sizeof(SPI_Obj));

    it will help to look through HAL to review what was done for SPIB

  • Christian Dold said:
    Does the SPI-B communication to the DRV8301 also work when i change the configuration of GPIO 24-26 as QEP2 to add a second Encoder to the System?

    No. per the HAL GPIO 24-26 are set as SPI-B

      // SPI SIMO B
      GPIO_setMode(obj->gpioHandle,GPIO_Number_24,GPIO_24_Mode_SPISIMOB);

      // SPI SOMI B
      GPIO_setMode(obj->gpioHandle,GPIO_Number_25,GPIO_25_Mode_SPISOMIB);

      // SPI CLK B
      GPIO_setMode(obj->gpioHandle,GPIO_Number_26,GPIO_26_Mode_SPICLKB);

    We will have a new 69M LaunchPad in January which has both QEP headers connected to a single 69M MCU.  I'm not sure you can add a 2nd on this EVM along with SPIA and SPIB.

    You would have to check the pin-mapping of the chip itself to see if you can get out both SPI and both QEP onto your own custom layout....I'm curious myself.

  • according to the pinmux tool

    \controlSUITE\device_support\~Utilities\PinMux_v103\

    and then verified via the datasheet

    yes, you can have both SPI and both QEP brought out in a custom hardware

    And of course you can, because that's exactly what our new LaunchPad does. We have a SPI going to each pair of LaunchPad headers, then both QEP brought to their own pin header connectors (like J10 on your board)

  • Hello again,

    thanks Chris for your tips.

    I have Problems with the spiA. I have doing the Setup like Spi B but i don't get any Signal at the Output and Inputpins,

    Here are my Sourcecode:

    //in proj_lab12b-MainISR
    
    if (oSendButton==true)
        {
    
        HAL_SPI_ReadSingleReg(halHandle, &u16OnlineStatus, u8RegAddr1, au8SPIReceivedata);
        //HAL_SPI_ReadServeralReg(halHandle, &u16OnlineStatus, u8RegAddr1, u8RegAddr2, au8SPIReceivedata);
        oSendButton=false;
    
    //in hal.c 
       
      // setup the spiA in HAL_setParams  
    HAL_setupSpiA(handle);
    
    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_setClkPhase(obj->spiAHandle,SPI_ClkPhase_Normal);
    	  SPI_enableTx(obj->spiAHandle);
    	  SPI_disableTxFifoEnh(obj->spiAHandle);	//geändert
    	  SPI_disableRxFifoInt(obj ->spiAHandle);	//eingefügt
    	  SPI_enableInt(obj->spiAHandle); //eingefügt
    	  //SPI_enableOverRunInt(obj->spiAHandle);	//eingefügt
    	  SPI_setBaudRate(obj->spiAHandle,(SPI_BaudRate_e)(0x0003));;
    	  SPI_setCharLength(obj->spiAHandle,SPI_CharLength_8_Bits);
    	  SPI_setSuspend(obj->spiAHandle,SPI_TxSuspend_free);
    	  //SPI_enableLoopBack(obj->spiAHandle);//hinzugefügt
    	  //SPI_setPriority(obj->spiAHandle,SPI_Priority_FreeRun);  //hinzugefügt
    	  SPI_enable(obj->spiAHandle);
    	  return;
    }  // end of HAL_setupSpiA() function
    
      //in SetupGPIO
      // SPI-SIMO
      GPIO_setMode(obj->gpioHandle,GPIO_Number_16,GPIO_16_Mode_SPISIMOA);					
    
      // SPI-SOMI
      GPIO_setMode(obj->gpioHandle,GPIO_Number_17,GPIO_17_Mode_SPISOMIA);			
    
      // SPI-CLK
      GPIO_setMode(obj->gpioHandle,GPIO_Number_18,GPIO_18_Mode_SPICLKA);			
    
      // SPI-STE
      GPIO_setMode(obj->gpioHandle,GPIO_Number_19,GPIO_19_Mode_SPISTEA_NOT);			
    

    //My own SPI-functions in HAL.c /*-------------------SPI - Message Command-------------------*/ void HAL_SPI_TransReceive(HAL_Handle tHandle, uint8_t *pu8WriteData, uint8_t *pu8ReadData) { HAL_Obj *obj = (HAL_Obj *)tHandle; SPI_write(obj->spiAHandle,(uint16_t)*pu8WriteData); while(1) //Warten bis Übertragung abgeschlossen { if(SPI_getIntFlagStatus(obj->spiAHandle)==SPI_IntFlagStatus_Completed) { *pu8ReadData=(uint8_t) SPI_read(obj->spiAHandle); *pu8ReadData=(*pu8ReadData>>(8)); break; } } return; } /*-------------------Read Single Register-------------------*/ void HAL_SPI_ReadSingleReg(HAL_Handle tHandle, uint_least16_t* u16OnlineStatus, uint8_t u8RegAddr, uint8_t *pu8ReceiveData) { //defines #define DUMMY_ADDR (0x3F) #define MASK_READ_BIT (0x80) u8RegAddr=((MASK_READ_BIT)||(u8RegAddr)); HAL_SPI_TransReceive(tHandle,&u8RegAddr,pu8ReceiveData); *u16OnlineStatus=(uint_least16_t) (*pu8ReceiveData<<(7)); u8RegAddr=DUMMY_ADDR; HAL_SPI_TransReceive(tHandle,&u8RegAddr,pu8ReceiveData); *u16OnlineStatus=(uint_least16_t) *pu8ReceiveData; HAL_SPI_TransReceive(tHandle,&u8RegAddr,pu8ReceiveData); return; }


    I hope anyone could help me. I doesn't no whats my failuir in the spi-configuration.

    I am using the Interrupt Flag without using the Fifo-Registers. Do i Need to set or reset any Interupt Registers?

    Thanks for help.

     

     

  • Hello,

    I just want to confirm, did you enable the peripheral clock?

    void HAL_setupPeripheralClks(HAL_Handle handle)
    {
      HAL_Obj *obj = (HAL_Obj *)handle;

    ...

      CLK_enableSpiaClock(obj->clkHandle); // The default is disabled. Should be enabled if you want to use it
    ...

    }

    Best regards,

    Maria

  • Yes i have enabled the peripheral clock. Have anyone another tip to getting the spi communication run.

    I am using a 8 Bit Transmission configuration. Could it be a Problem in the writing on the Buffers?

    Do i Need no Interrupt configuration for this SPI? My Project is based on Lab12b of InstaSpin Motion.

    Thank you for help

    Regands,

    Christian

  • Hello,

    Again I want to confirm,

    Did you put SPI_init in HAL_init(void *pMemory,const size_t numBytes) (in hal.c)?


  • Christian Dold said:
    Do i Need no Interrupt configuration for this SPI

    You need to enable the SPI INT bit in PIE if you want SPI interrupt.

    You need to call the PIE function, just like for example: PIE_enablePwmInt() or PIE_enableTimer0Int() in pie.c

    Have you set this PIE bit?

    Also for CPU INT bit for the INT (I think it is INT6), just like for example:

    // enable the cpu interrupt for ADC interrupts
      CPU_enableInt(obj->cpuHandle,CPU_IntNumber_10);


  • I got the reason. I was a Problem with the DRV8301-HC-C2 Board. There is a Device which Isolate the SPI of the C2000. So the C2000 could only use as Slave. After i remove this Device and Bridge it i got the SPI Signals.

     

    I have one Problem left with this Signal. 

    I would change Polarity of the STE Signal with the function  

    SPI_setSteInv(obj->spiAHandle,SPI_SteInv_ActiveHigh)

    But the Signal doesn't Change the Polarity. What could be the Problem?

    Thanks for answer

    Regards Christian