Module:
—Q2686 SPI1 Master mode 0, Speed 101KBps, POL Low, MSB First, Word Handling, 3 wires CSnone UNDIR ( SPI-IO, SPI-I, CLK)
—TI MSP430F2274 Slave mode 0,
Result or problem:
SPI1 write is always OK. For example, busWrite by every one second always successful.
SPI1 first time read is successful, then program will fry or halt when I try the second read or write.
Source Code:
#define RX_SIZE 6
#define TX_SIZE 6
static u8 RXBuffer[RX_SIZE], TXBuffer[TX_SIZE];
static s32 EuclaseSPIHandle; //Bus handle
const adl_busSPISettings_t EuclaseSPIConfig =
{
127, // 112 - 115200bps, 127 - 101 kbps
ADL_BUS_SPI_CLK_MODE_0, // Mode 0 clock, rest state 0, data valid on rising edge
ADL_BUS_SPI_ADDR_CS_NONE,
ADL_BUS_SPI_CS_POL_LOW, // Chip Select signal is activated in low edge
ADL_BUS_SPI_MSB_FIRST, // MSB first
ADL_IO_Q2686_GPIO_31, // SPI1-CS
ADL_BUS_SPI_WORD_HANDLING, // R/W by word size
ADL_BUS_SPI_DATA_UNIDIR // 2 pins are used to handle separately I/O data signals
};
adl_busAccess_t AccessConfig = //Access configuration structure
{
0,0,0,0, // No opcode, no address
ADL_BUS_SIZE_BYTE // byte (u8) data buffer
};
const u16 wm_apmCustomStackSize = 1024;
/****************************************************************************/
void MyTimerHandler ( u8 ID )
{
static int counter=0;
if(counter)
{
counter=0;
adl_busRead(EuclaseSPIHandle, &AccessConfig, 5, RXBuffer);
adl_atSendResponse ( ADL_AT_UNS, "\r\n SPI1 Read Every Second \r\n" );
}
else
{
counter++;
adl_busWrite(EuclaseSPIHandle, &AccessConfig, 5, TXBuffer);
adl_atSendResponse ( ADL_AT_UNS, "\r\n SPI1 Write every second \r\n" );
}
}
/**************************************************************/
void adl_main ( adl_InitType_e InitType )
{
TRACE (( 1, “Embedded : Appli Init” ));
TXBuffer[0]='@';
TXBuffer[1]=0xa1;
TXBuffer[2]=0xa2;
TXBuffer[3]=0xa3;
TXBuffer[4]='$';
TXBuffer[5]='\0';
RXBuffer[0]=0xa1;
RXBuffer[1]=0xa2;
RXBuffer[2]=0xa3;
RXBuffer[3]=0xa4;
RXBuffer[4]=0xa5;
RXBuffer[5]='\0';
/* Set 1s cyclic timer =10*100ms=1second */
adl_tmrSubscribe ( TRUE, 10, ADL_TMR_TYPE_100MS, MyTimerHandler );
EuclaseSPIHandle = adl_busSubscribe(ADL_BUS_SPI1, &EuclaseSPIConfig); // Initiate SPI1
if(EuclaseSPIHandle<0)
{
adl_atSendResponse(ADL_AT_UNS, "\r\n SPI Bus Initiate Fail\r\n");
}
}