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.

Getting problem in ssi communication in tm4c123gh6pm

Other Parts Discussed in Thread: TM4C123GH6PM

HI

I am using tm4c123gh6pm Launchpad.I try to interface digital pot mcp41010 Via SSI communication.but i am getting a problem below i paste my code plz verify and tell is there any mistake in that

#include <stdint.h>
#include <stdbool.h>
#include "C:\Users\admin\inc\hw_types.h"//"inc/hw_types.h"
#include "C:\Users\admin\inc\hw_memmap.h"//"inc/hw_memmap.h"
#include "C:\Users\admin\driverlib\sysctl.h"//"driverlib/sysctl.h"
#include "C:\Users\admin\driverlib\gpio.h"//"driverlib/gpio.h"
#include "C:\Users\admin\inc\tm4c123gh6pm.h"
#include "C:\Users\admin\driverlib\timer.h"
#include "C:\Users\admin\driverlib\interrupt.h"
#include "C:\Users\admin\driverlib\ssi.h"

unsigned int d;
#define CS GPIO_PIN_1


void delay_ms(int del)
{
del=((SysCtlClockGet()/3)*del/1000);
SysCtlDelay(del);
}
void ssi_init()
{
SysCtlPeripheralEnable(SYSCTL_PERIPH_SSI0);
SysCtlPeripheralReset(SYSCTL_PERIPH_SSI0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);

GPIOPinTypeSSI(GPIO_PORTA_BASE, GPIO_PIN_2|GPIO_PIN_5);


GPIOPinWrite(GPIO_PORTE_BASE, GPIO_PIN_1,2);

GPIOPinConfigure(0x00000802); //sck
GPIOPinConfigure(0x00001402); //SO

SSIConfigSetExpClk(SSI0_BASE, SysCtlClockGet(), SSI_FRF_MOTO_MODE_0, SSI_MODE_MASTER, 200000, 16);// 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, 0); //CS = 0;
delay_ms(500);
SSIDataPut(SSI0_BASE,0x11);
SSIDataPut(SSI0_BASE,0x00);while(SSIBusy(SSI0_BASE));
delay_ms(100); //mcp write
SSIDataPut(SSI0_BASE,0xFF);
SSIDataPut(SSI0_BASE,0x00); while(SSIBusy(SSI0_BASE));
delay_ms(100);
//SSIDataPut(SSI0_BASE,0x00);while(SSIBusy(SSI0_BASE)); dly(100); //value to be written
GPIOPinWrite(GPIO_PORTE_BASE, CS, 2); //CS = 1;
}


int main()
{
SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
GPIOPinTypeGPIOOutput(GPIO_PORTE_BASE, GPIO_PIN_1);//CS

ssi_init();delay_ms(50);
while(1)
{
mcp(10);
}
}

i continuously getting an output at mcp 2.5v only for all the values 

  • Hi Asha,

    I find funny that you took the time to distinguish the functions by colors but you didn't indent the code :p

    Many things are wrong or not that great on your code.
    In ssi_init():
    -Why would you write a digital value to the pin?
    -Why in PinConfigure did you use hexadecimal values instead of the macros? Are they correct?
    - in SSIConfigSetExpClk() there you use the SysCtlClockGet function which right now has a bug but I am not sure if at 40Mhz it happens, can you check the output?


    Another thing - can you perform a debug? Can you check if the code is stuck somewhere?
  • Suspect poster wrote to the SSI_CS pin "digitally" as that's quicker/easier. (and appears that he got that right.

    Code review (for others) - I'd ask if the remote pot is correctly powered - to include a common ground between MCU board and the digital pot. Have all of the wires been "ohm'ed out" between MCU & pot? And - has the MCU's MISO pin (unused by poster {and his pot}) been "pulled-up" - just in case?
  • Hello Asha

    MCP41010 uses a command byte in the MSB position and data byte in the LSB position. The command byte in this case is 0x0!!!! Could that be the source of the issue.

    Regards
    Amit