在中断里放上OSSemPost ()发送信号量后,程序运正就不正常了, 明显的不对就是OSTimeDlyHMSM()都无效了, 任务执行频繁,还请高手指点一二。
我用的是STM32F103VE,架的是UCOS系统, 原来键了两个任务,一个是LCD显示,一个是键键处理,运行的没有错。后来加了I2C任务,配合I2C中断读取外部ADC芯片数据,只要是在I2C中断中加入OSSemPosvoid I2C2_EV_IRQHandler(void)
{
OS_CPU_SR cpu_sr;
OS_ENTER_CRITICAL();
OSIntNesting++;
OS_EXIT_CRITICAL();
switch (I2C_GetLastEvent(I2C2))
{
case I2C_EVENT_MASTER_MODE_SELECT: /* EV5 */
OSSemPost (I2CAckSem);
// Master Receiver -------------------------------------------------
// Send slave Address for read
I2C_Send7bitAddress(I2C2, LTC2453_ADDR, I2C_Direction_Receiver);
break;
// Master Receiver -------------------------------------------------------
// Test on I2C2 EV6 and clear them /* EV6 */
case I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED:
// ENABLE I2C2 acknowledgement
I2C_AcknowledgeConfig(I2C2, ENABLE);
break;
// Test on I2C2 EV7 and clear it
case I2C_EVENT_MASTER_BYTE_RECEIVED: /* EV7 */
// Store I2C1 received data
ADCValueUnion.ADCR[ CycDec1(7, I2CPortStruct.ADC_Channel) ][I2CPortStruct.Rx1_Idx--] = I2C_ReceiveData(I2C2);
// Disable ACK and send I2C1 STOP condition before receiving the last data
if(I2CPortStruct.Rx1_Idx == 0)
{
// Disable I2C2 acknowledgement
I2C_AcknowledgeConfig(I2C2, DISABLE);
// Send I2C2 STOP Condition
I2C_GenerateSTOP(I2C2, ENABLE);
}
else OSSemPost (I2CReceiveSem);
break;
case I2C_EVENT_SLAVE_ACK_FAILURE: /* EV3_2 */
I2C_GenerateSTOP(I2C2, ENABLE);
break;
default: break;
}
OSIntExit();
}
t ()就不对。弄了好几天了,实在不行了上来求教。
在I2C中断中加入OSSemPost ()的位置是/* EV5 */,查看是否起始位发送成功。接收这个信号量的是处理I2C的任务。 |