Other Parts Discussed in Thread: MSP-EXP430F5529LP
Tool/software: Code Composer Studio
Hi, I am new to msp430 and now I have a problem using msp430 SPI interface.
I want to test the SPI interface, but after I connect the logic analyzer with msp, the SPI signal was not sent out. the CLK and MOSI stay low all the time. I am wondering if it is the problem with the board. if yes, how can I test it. I actually tried the sample code of SPI provided by TI, but it doesn't work either.
Following is my code. it will repeatedly send 0x00 and 0xc8.
#include "driverlib.h"
#define SPICLK 1000000
uint8_t returnValue = 0x00;
void SendCodeSPI(uint8_t data);
void main (void)
{
WDT_A_hold(WDT_A_BASE);
//__enable_interrupt();
//Set P1.1 for slave reset
/*GPIO_setAsOutputPin(
GPIO_PORT_P1,
GPIO_PIN2
);*/
GPIO_setAsOutputPin(
GPIO_PORT_P1,
GPIO_PIN3
);
//P3.5,4,0 option select
GPIO_setAsPeripheralModuleFunctionInputPin(
GPIO_PORT_P3,
GPIO_PIN0+GPIO_PIN2
);
//Initialize Master
USCI_B_SPI_initMasterParam param = {0};
param.selectClockSource = USCI_B_SPI_CLOCKSOURCE_ACLK;
param.clockSourceFrequency = UCS_getACLK();
param.desiredSpiClock = SPICLK;
param.msbFirst = USCI_B_SPI_MSB_FIRST;
param.clockPhase = USCI_B_SPI_PHASE_DATA_CAPTURED_ONFIRST_CHANGED_ON_NEXT;
param.clockPolarity = USCI_B_SPI_CLOCKPOLARITY_INACTIVITY_LOW;
returnValue = USCI_B_SPI_initMaster(USCI_B0_BASE, ¶m);
if (STATUS_FAIL == returnValue){
return;
}
//Enable SPI module
/*GPIO_setOutputHighOnPin(
GPIO_PORT_P1,
GPIO_PIN2
);*/
USCI_B_SPI_enable(USCI_B0_BASE);
//Enable Receive interrupt
//Wait for slave to initialize
__delay_cycles(1000);
GPIO_setOutputHighOnPin(
GPIO_PORT_P1,
GPIO_PIN3
);
while(1){
USCI_B_SPI_transmitData(USCI_B0_BASE, 0x00);
while(USCI_B_SPI_isBusy(USCI_B0_BASE));
USCI_B_SPI_transmitData(USCI_B0_BASE, 0xC8);
while(USCI_B_SPI_isBusy(USCI_B0_BASE));
};
/*while(true)
{
SendCodeSPI(0x00);
__delay_cycles(1000000);
SendCodeSPI(0xFF);
__delay_cycles(1000000);
}*/
}
void SendCodeSPI(uint8_t data)
{
GPIO_setOutputLowOnPin(
GPIO_PORT_P1,
GPIO_PIN2
);
__delay_cycles(1000);
USCI_B_SPI_transmitData(USCI_B0_BASE, 0x00);
while(USCI_B_SPI_isBusy(USCI_B0_BASE));
USCI_B_SPI_transmitData(USCI_B0_BASE, data);
while(USCI_B_SPI_isBusy(USCI_B0_BASE));
GPIO_setOutputHighOnPin(
GPIO_PORT_P1,
GPIO_PIN2
);
__delay_cycles(10000);
}

