Hi, everyone~
I don't live in an English-speaking country.
So, please understand even if the grammar is not correct:)
To begin with, I have difficulty developing SPI slave mode communication code.
My hardware infomation is as follows.
Master Slave
(SPC5748G B/D) (MSP430FR2355 B/D)
----------------------- ---------------------
SIMO | -----------> | SIMO (P1.2)
SCK | -----------> | SCK (P1.1)
GND | -----------> | GND
VCC | -----------> | VCC
----------------------- ---------------------
Master SPI's setting information is baudrate 200kHz, clockPolarity is Active High, clockPhase is First Edge, msbFirst.
One-way communication is being made from Master to Slave via just two wire.
However, the data sent from Master does not receive at Slave correctly
Master sends data of '0x04', but Slave receives completely different data like '0x0D'.........
Just in case, I connected Master(SPC5748G B/D) and Arduino Uno(SPI slave mode) and tested it, and Master confirmed that they send data correctly
I'll leave my code below for your check.
-----------------------------------------------------------------------------------------------
#include "driverlib.h"
uint8_t transmitData = 0x01
uint8_t receiveData[100] = {0, };
void main(void)
{
//Stop watchdog timer
WDT_A_hold(WDT_A_BASE);
GPIO_setAsPeripheralModuleFunctionInputPin(
GPIO_PORT_P1,
GPIO_PIN1 + GPIO_PIN2 + GPIO_PIN3,
GPIO_PRIMARY_MODULE_FUNCTION
);
PMM_unlockLPM5();
//Initialize slave to MSB first, inactive high clock polarity and 3 wire SPI
EUSCI_B_SPI_initSlaveParam param = {0};
param.msbFirst = EUSCI_B_SPI_MSB_FIRST;
param.clockPhase = EUSCI_B_SPI_PHASE_DATA_CHANGED_ONFIRST_CAPTURED_ON_NEXT;
param.clockPolarity = EUSCI_B_SPI_CLOCKPOLARITY_INACTIVITY_HIGH;
param.spiMode = EUSCI_B_SPI_3PIN;
EUSCI_B_SPI_initSlave(EUSCI_B0_BASE, ¶m);
//Enable SPI Module
EUSCI_B_SPI_enable(EUSCI_B0_BASE);
EUSCI_B_SPI_clearInterrupt(EUSCI_B0_BASE,
EUSCI_B_SPI_RECEIVE_INTERRUPT
);
//Enable Receive interrupt
EUSCI_B_SPI_enableInterrupt(EUSCI_B0_BASE,
EUSCI_B_SPI_RECEIVE_INTERRUPT
);
__bis_SR_register(GIE); // enable interrupts
while(1)
{
}
}
//******************************************************************************
//
//This is the USCI_B0 interrupt vector service routine.
//
//******************************************************************************
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=USCI_B0_VECTOR
__interrupt
#elif defined(__GNUC__)
__attribute__((interrupt(USCI_B0_VECTOR)))
#endif
void USCI_B0_ISR (void)
{
receiveData[index] = EUSCI_B_SPI_receiveData(EUSCI_B0_BASE);
index++;
if(index >= 100)
{
index = 0;
}
}
-----------------------------------------------------------------------------------------------
I’d be glad if you could help me.
Thanks.