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.

problem in SSIDataPut() while communicating with mcp



Hi Amit,

here i have a problem with ssi module. I'm using tm4c123 launchpad. In my program i'm transmitting command to the external mcp41010.....  but  by seeing my output from mcp, it is reveal that my data was not transmitted properly..... I dont know that where i did mistake..... 

its my program:

#include<stdint.h>
#include<stdbool.h>
#include<hw_memmap.h>
#include<hw_types.h>
#include<sysctl.h>
#include<gpio.h>
#include<ssi.h>
#define CS GPIO_PIN_1  //GPIO PIN for Slave Select

void dly(unsigned int ms)
{
ms=(SysCtlClockGet()/3.0)*ms/1000;
SysCtlDelay(ms);
}

void ssi_init(){

SysCtlPeripheralEnable(SYSCTL_PERIPH_SSI0);       //SSI ENABLE
SysCtlPeripheralReset(SYSCTL_PERIPH_SSI0);         //Reset ssi mode

SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);    //ENABLE GPIOA
GPIOPinTypeGPIOOutput(GPIO_PORTA_BASE, GPIO_PIN_2|GPIO_PIN_5);       //SCK, SO
GPIOPinTypeGPIOInput(GPIO_PORTA_BASE, GPIO_PIN_4);            //SI

          SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);                   //ENABLE GPIOE
          GPIOPinTypeGPIOOutput(GPIO_PORTE_BASE, GPIO_PIN_1);// PE1 as output

GPIOPinConfigure(GPIO_PA2_SSI0CLK);             //sck
//GPIOPinConfigure(GPIO_PA4_SSI0RX);               //SI  it is not necessary. bcoz mcp wont transmit anything
GPIOPinConfigure(GPIO_PA5_SSI0TX);               //SO

GPIOPinTypeSSI(GPIO_PORTA_BASE, GPIO_PIN_2|GPIO_PIN_4|GPIO_PIN_5);
SSIClockSourceSet(SSI0_BASE, SSI_CLOCK_SYSTEM);              // sets the system clock as the source of clock

SSIConfigSetExpClk(SSI0_BASE, SysCtlClockGet(), SSI_FRF_MOTO_MODE_0, SSI_MODE_MASTER, 20000000, 8);// defines base, System clk, Mode 0 = SPH = SPO = 0,Master, 125 KHz, no. of bits = 8 = 1 byte transfer
SSIEnable(SSI0_BASE); //enables SSI

}

void mcp(unsigned char dat)
{
            GPIOPinWrite(GPIO_PORTE_BASE, CS, ~CS);                             //CS = 0;
           dly(500);

            //value transmitted from Controller

           SSIDataPut(SSI0_BASE,0x11);while(SSIBusy(SSI0_BASE)); dly(100); //mcp write
           SSIDataPut(SSI0_BASE, dat);while(SSIBusy(SSI0_BASE)); dly(100);  //value to be written


          GPIOPinWrite(GPIO_PORTE_BASE, CS, CS);                                              //CS = 1;
}

void main()

{
                  SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_OSC_MAIN|SYSCTL_XTAL_16MHZ);

                 ssi_init();dly(200);
                 

                 while(1)
                 {
                          mcp(0);
                 }
}

always i'm reading 2.5v from mcp........... 

  • Hello Rukmani,

    First of all even if the device does not send back any data the SSI receive FIFO flush may still be required for the reasone that if someone decides to replace MCP41xxx with MCP42xxx then they have to figure out where to flush or read data.

    Secondly, when configuring the CS ensure that the CS is in it's idle state of 1.

    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); //ENABLE GPIOE
    GPIOPinTypeGPIOOutput(GPIO_PORTE_BASE, GPIO_PIN_1);// PE1 as output
    GPIOPinWrite(GPIO_PORTE_BASE, GPIO_PIN_1, GPIO_PIN_1);

    Thirdly what is RS and SHDN pins connected.

    Lastly do you have a Scope or LA plot and did you check that the mode of configuration is as is expected by the MCP device?

    Regards
    Amit