Hi i want to have a rule when to disable global interrupt and how.
Situation:
MSP430F1611:
- I2C Master sending data to I2C Slave every 4 minutes.
- Using TimerB for increasing ticks in every ms and sec using timer ISR (CCR0 for sec / CCR1 for ms)
- LPM3 + GIE
MSP430F2132:
- I2C Slave receiving data from I2C Master every 4 minutes
- Using TimerA for generating tick in every ms and sec using timer ISR (CCR0 for sec / CCR1 for ms)
- LPM3 + GIE
Looks like Timer B ISR in I2C Master(1611) is preventing I2C write in weird way.
Or still I have I2C issues.
I2C Master Write And Read function are all implemented by polling I2C IFGs. ( No I2C Interrupt enabled for Master)
And every step is checked and generate reports when ERROR is detected by using timeout function (Timer A in 1611)
I2C Master Write Flow:
// before initiating the transfer, check bus is busy or not
while (I2CDCTL & I2CBB)
{
if(i2cTimeOut) { return ERROR_BUS_BUSY;}
}
// after start and stop condition is set ( I used I2CRM = 0 option, so i set them before I load data to buffer)
while((I2CIFG & TXRDYIFG) == 0)
{
if(i2cTimeOut) { return ERROR_TIMEOUT;}
}
I2CDRB = Data;
// after last byte is loaded to buffer wait for the transfer to be finished
while ((~I2CIFG) & ARDYIFG)
{
if(i2cTimeOut) { return ERROR_TRANSFER_TIMEOUT;}
}
And while write I2C data to slave, ms Tick timer ISR also running.
And i get ERROR_BUS_BUSY report from time to time.
I cannot re-create the situation. this happens sporadically.
Looks like I2CBB is not reset for some reason.
So i got rid of I2CBB check as I check ARDYIFG for checking transfer completion at the end anyway.
But then i SOMETIMES get ERROR_TRANSFER_TIMEOUT error.
So i thought "ms timer B ISR" has something to do with this.
So i turned the tick timer off from I2C Master when I2C data is transferring.
This definitely improved the situation but i still get ERROR_TRANSFER_TIMEOUT error once in a while.
Question:
So I read some threads and articles, and this might be something to do with not disabling interrupts while i'm doing critical things.
Critical Sections / Atomic Sections were told. Word read / write is Ok. but other than that something has to be done.
I still do not know whether my problems has to do with critical section protections or I2C modules issues ( esp. i have issues with I2CBUSY / I2CBB / ARDYIFG)
But if i need to set critical sections. what is best way to do this? I'm using CCS 5
_DINT();
do_criticalthing();
_ENIT();
is this enough? some people are storing SR values before _DINT(); and restore SR after _EINT();
Do you also think ms tick timer ISR can change the I2C hardware states or IFGs? when the code is waiting for it to be changed?
Sorry for the long question and thank you in advance.
hojun