Guys sorry for my poor format for the same issue previously....
Hey Linq,
A good news infact for your valuable support , today I was able to comunicate with I2C , almost 90% is done . Can you help me out for these issues listed below ..
the state where i get data ,i.e
case 0x50 ( Data Recieved with ACK) : Master_Buff[Read_Index] = I2DAT ; Read_Index++; if(Read_Index != MAX_READ) { I21CONSET = 0x04 (ACK bit) } else { Read_Index = 0; I21CONSET = 0x10 (stop) }
When I track Master_Buff 's value and use it within the Interrupt using UARTBYte out under CASE 0x50 , i get the correct data .
When I track Master_Buff''s value outside the IRQ and use it in my main , i am not getting the data .
To be noted that Master_Buff is a global variable , Then where should be the problem ???
Thanks for your support !
Looking forward, Samjith
Hi Samjith Wasim,
Please do NOT create new thread everytime when you just want to reply/update to your identical question/problem.
If you create new thread everytime, then we are not able to know your progress correctly and not able to check you code easily.
According to your another thread:
Your Code:
void main(void) { PCONP |= 0x00080000; PINSEL1 |= 0x000003C0; /* Setting Pin Selection for I2C1 */ I21SCLL = 60; /* Speed at 100Khz */ I21SCLH = 60; VICIntEnClr |= (1<<19); VICVectPriority19 = 1; VICVectAddr19 = (unsigned long)I2C_IRQHandler; VICIntEnable |= (1<<19); while(1) { I21CONSET = 0x00000040; /* Setting I2Enable bit */ I21CONSET = 0x00000020; /* Setting Start Bit */ if(Message == 1) { LcdDisplay("Message is 1"); } and so on....till Message == 23.. }
If the above code remains your main() function, then [you can not get the data you want in main() function] is due to [ISR runs very quickly, when ISR finishs its work, main() has not started to work].
i2c.h
#define I2CONCLR_AAC 0x00000004 #define I2CONCLR_SIC 0x00000008 #define I2CONCLR_STAC 0x00000020 #define I2CONCLR_I2ENC 0x00000040
i2c.c
I20CONCLR = (I2CONCLR_SIC | I2CONCLR_STAC);
Use the above coding style, your code would be easier to read and understand.
Please read the LPC23XX User manual, Chapter 21: LPC23XX I2C interfaces I2C0/1/2, 6.2 Master Receiver mode, Fig 105. Format of Master Receive mode.
And make sure that your code follows the I2C Master Receive standard.
For example, before you send STOP, you should send [Not acknowledge] first.
If you don't 100% follow the I2C standard, your code may work, with some strange behaviors.
Hello linq ,
Like you told I have declared the global variable as "volatile" and followed setting up the NACK bit before setting the stop bit like this ,
case 0x50: MasterBuff[Index] = I21DAT ; if(Index != READ_SIZE) { I21CONSET = SET_ACK_BIT; Index++; } else { Index = 0; I21CONCLR = SEND_NACK_BIT; I21CONCLR = STOP_BIT; I21CONCLR = CLEAR_INTERRUPT_BIT; }
but still I am not able to get the desired result .
Looking forward,
Sam
1. Please provide the source code of your main().
2. Please re-read the manual, re-write your code.
3. Please trace your code step by step.
I have used the Debugging tool and simulated it to see I2C interrupt ; all the status are getting updated , it is entering into case 0x50 . This is my main ,
void main() { I2C_init(); while(True) { I2C_SET_START_BIT ; } }
void main() { I2C_init(); while(True) { I2C_SET_START_BIT ; if(MasterBuffer[0] == 1) Disp (1); else if (MasterBuffer[1] == 2) Disp (2); Similarly upto MasterBuffer[23]... } }
What is the result you expect?
What is the result you get?
What is "I2C_SET_START_BIT"?
What is "Disp (x)"?
Is Salihu Aliyu your classmate?
Hey Linq ,
Surprisingly , when I checked under case 0x50 I came to know even after exceeding my Read Index my ACK bit was set,When I cleared that bit once for all , I couldn't beleive myself that I got the desired result .
Sir about Salihu Aliyu , Could i Know whose that person ???
Thanks for all your Inputs and support Linq ,
Regards, Samjith.
but his name is John, not Linq...
You still need to:
1. Please re-read the manual, re-write your code.
2. Please trace your code step by step.
I believe that, there are some other bugs in your code.
Hey John ,
Since the application which I am working on is a real-time appn . I modified the code as told by you and checked for all the test cases , its working fine ...
Thanks for your Support !!!
Regards, Samjith