工具/软件:TI-RTOS
大家好
最近、我在 MSP_EXP430F5529LP 开发 板上配置了 SPI 主器件和 SPI 从器 件、在 TI-RTOS 两个任务下、我发现两个 SPI 相互交互。 当我关闭其中一个任务而另一个 SPI 工作正常时, 我尝试添加信标以保护 SPI_TRANSF()功能,问题仍然存在, 我放置断点,发现问题出现在下图中,导致 SPI 传输返回错误, SPI 从器件只能向外发送第一个字节。 谁能教我如何做、或者给我一个类似的例子、谢谢!
此致
XC.mo
2.代码
#define spiA1_TASKSTACKSIZE 512
SPI_Handle spiA1_master;
spi_Params spiA1_master_params;
Task_Structt spiA1_master_taskStructt;
char spiA1_master_taskStack[spiA1_TASKSTACKSIZE];
GateMutex_handle gatemutex_handle;
GateMutex_Params gatemutex_params;
#define spiB1_TASKSTACKSIZE 512
SPI_Handle spiB1_slave;
SPI_Params spiB1_slave_Params;
Task_Structt spiB1_slave_taskStructt;
Char spiB1_slave_taskStack[spiB1_TASKSTACKSIZE];
//semaphore_handle spiB1_semHandle;
Semaphore_Params spiB1_semParams;
Semaphore_Structp1_semStructP;
//semaphore_handle protect SPI_transfer ()
semaphore_Params two_SPI_semParams;
semaphore_Structt two_SPI_transferStructP;
//
// void spiA1transferCallbackFxn (SPI_handle、SPI_transaction_semCI_transaction*
;{smain_transfer_transaction_transaction_1s_transaction_high_transaction_transaction_transaction_s*;
Semaphore_post (Semaphore_handle (&two_SPI_semStructP));
system_printf ("spiA1 transferCallbackFxn inter!\n");
system_flush();
}/*
==== uscia1_SPI taskFxn ===
*此函数的任务是静态创建的。 请参阅工程的.cfg 文件。
//
void spiA1_master_taskFxn (UArg0、UArgarg1)
{
/*创建 I2C 以供使用*/
SPI_PARAMS_INIT (&spiA1_MASTER_PARAMS);
spiA1_master_Params.transferMode = SPI_MODE_CALLACK;
spiA1_master_Params.transferCallbackFxn = spiA1transferCallbackFxn;
spiA1_master_Params.mode = SPI_MASTER;
spiA1_master_Params.bitrate = 50000、 /*比特率 Hz*/
spiA1_master_Params.dataSize = 8;
spiA1_master_Params.frameFormat = SPI_POL1_PHA1;
spiA1_master = SPI_open (Board_SPIA1_master、&spiA1_MASTER_Params);
if (spiA1_master == NULL){
System_abort ("初始化 SPI\n"时出错);
}
否则{
system_printf ("spiA1已初始化!\n");
}
system_flush();
//gatemute
GateMutex_Params_init (&G);
gatemutex_handle = GateMutex_create (&gatemutex_params、NULL);
if (gatemutex_handle = NULL){
System_abort ("错误 GateMutex_create\n");
}
否则{
System_printf ("GateMutex_create OK!\n");
}
char txbuf[5]={0x21、0x22、0x23、0x24、0x25};
char rxbuf[6];
uint8_t 计数;
SPI_Transaction spiTransaction;
while (1){
//Cs 低电平
Board_SPIA1_MASTER_CS_LOW;
Semaphore_pend (Semaphore_handle (&two_SPI_semStructP)、BIOS_wait_forever);
spiTransaction.txBuf = txbuf;
spiTransaction.rxBuf =空;
spiTransaction.count = 5;
if (SPI_transfer (spiA1_master、&spiTransaction)= NULL){
System_printf ("spiA1总线故障\n");
system_flush();
}
Task_sleep (1000);
GPIO_TOGGLE (Board_LED_P1_0);;
}
}
void spiB1_CS_Fxn1 (UArg arg)
{
Semaphore_post (semaphore_handle (&spiB1_semStructP));
//System_printf ("spiB1 CS P2_4中断回调!\n");
//System_flush();
}
void spiB1_slave_taskFxn (UArg0、UArgarg1)
{
/*创建 SPI 供使用*/
SPI_PARAMS_INIT (&spiB1_SLAVE_PARAMS);
spiB1_SLAVE_PARAMS.transferMode = SPI_MODE_CALLACK;
spiB1_slave_Params.transferCallbackFxn = spiB1_transferCallbackFxn;
spiB1_SLAVE_PARAMS.MODE = SPI_SLAVE;
spiB1_slave_Params.dataSize = 8;
spib1_slave = SPI_open (Board_SPIB1_slave、&spib1_slave_Params);
if (spiB1_slave = NULL){
System_abort ("初始化 SPI B1\n"时出错);
}
否则{
System_printf ("SPI B1已初始化!\n");
}
system_flush();
//gatemute
GateMutex_Params_init (&gatemutex_spiB1_params);
gatemutex_spiB1_handle = GateMutex_create (&gatemutex_spiB1_params、NULL);
if (gatemutex_spiB1_handle = NULL){
system_abort ("错误 gatemutex_spiB1_create\n");
}
否则{
system_printf ("gatemutex_spiB1_create OK!\n");
}
system_flush();
//CS 信标
Semaphore_Params_init (&spiB1_semParams);
spiB1_semParams.mode = semaphore_Mode_binary;
Semaphore_construction (&spiB1_semStructP、0、&spiB1_semParams);
//启用 CS (P2_4)中断
GPIO_setCallback (Board_SPIB1_SLAVE_CS_P2_4、(GPIO_CallbackFxn) spib1_CS_Fxn1);//大量早于 GPIO_enableInt ()
GPIO_enableInt (Board_SPIB1_SLAVE_CS_P2_4);
char txbuf[5]={0x12、0x13、0x14、0x15、0x16};
SPI_Transaction spiTransaction spiTransaction;
Task_sleep (100);
while (1){
//根据 GPIO 中断判断 CS
Semaphore_pend (Semaphore_handle (&spiB1_semStructP)、BIOS_WAIT_FOREVE);
//保护 SPI_transfer ()
semaphore_pend (semaphore_handle (&two_SPI_semStructP)、BIOS_wait_forever);
spiTransaction.txBuf = txbuf;
spiTransaction.rxBuf = NULL;
spiTransaction.count = 5;
if (SPI_transfer (spiB1_slave、 &spiTransaction)=NULL){
System_printf ("spiB1总线故障\n");
System_flush ();
}
semaphore_post (semaphore_handle (&two_spi_semStructP));
Task_sleep (1000);
GPIO_toggle (Board_LED_P4_7);
}
}
int main (void)
{
/*呼叫板初始化函数*/
Board_initGeneral();
Board_initGPIO();
Board_initSPI();
//SPI 主器件
taskParams.arg0 = 1000;
taskParams.STACKSIZE = spiA1_TASKSTACKSIZE;
taskParams.stack = spiA1_master_taskStack (&S);
Task_construction (&spiA1_master_taskStruct,(Task_Functr) a1_master_taskFxn、&taskParams、NULL);
//spiB1从属设备
taskParams.arg0 = 1000;
taskParams.STACKSIZE = spiB1_TASKSTACKSIZE;
taskParams.stack = spiB1_slave_taskStack;
Task_construct(&spiB1_slave_taskStruct,(Task_Functr )spiB1_slave_taskFxn,&taskParams,NULL );
//stwo_SPI 信号量受保护的 SPI_transfer ()
Semaphore_Params_init (&two_SPI_semParams);
spiB1_semParams.mode = semaphore_Mode_binary;
Semaphore_construction (&two_SPI_semStructP、1、&two_SPI_semParams);
/*启动 BIOS */
BIOS_start();
返回(0);
}

