Other Parts Discussed in Thread: ENERGIA
Tool/software: TI C/C++ Compiler
I tried to interface the Digital Potentiometer MCP4131 with the Tiva TM4C123GXL LaunchPad through SPI. An LED was connected to the output of MCP4131. Referring the data sheet and videos the code was written, compiled and programmed using Keil uvision5. SPI pins were not giving any signals when checked using DSO. The code is as given below. Please find out the error and devise a solution.
#include <stdint.h>
#include <stdlib.h>
#include "TM4C123GH6PM.h"
void spi_master_ini(void){
SYSCTL->RCGCSSI|=(1<<2);
SYSCTL->RCGC2|=(1<<1);
GPIOB->AFSEL|=(1<<4)|(1<<6)|(1<<7);
GPIOB->AFSEL&=~(1<<5);
GPIOB->PCTL|=(2<<16)|(2<<20)|(2<<24)|(2<<28);
GPIOB->DEN|=(1<<4)|(1<<5)|(1<<6)|(1<<7);
GPIOB->DIR|=(1<<5);
GPIOB->PUR|=(1<<4)|(1<<5)|(1<<6)|(1<<7);
SSI2->CR1&=(1<<1);
SSI2->CR1=0x00000000;
SSI2->CC=0x00;
SSI2->CPSR=8;
SSI2->CR0=(0x7<<0);
SSI2->CR1|=(1<<1);
}
void SPI_write(uint8_t data){
SSI2->DR=data;
while((SSI2->SR&(1<<0))==0);
}
int main(){
SystemInit();
spi_master_ini();
GPIOB->DATA|=(1<<5);
GPIOB->DATA&=~(1<<5);
SPI_write(0x00);
for(int j=0;j<128;j++)
SPI_write(j);
for(int i=0;i<15;i++)
GPIOB->DATA|=(1<<5);
while(1)
{
GPIOB->DATA&= ~(1<<5);
SPI_write(0x00);//sending string
for(int j=0;j<128;j++)
SPI_write(j);
for(int i=0;i<15;i++)
GPIOB->DATA|=(1<<5);
}
return(0);
}