Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] Not Getting Proper Status Responses of Repeated Start in I2C Protocol of LPC1343?

Status
Not open for further replies.

xpress_embedo

Advanced Member level 4
Advanced Member level 4
Joined
Jul 5, 2011
Messages
1,154
Helped
161
Reputation
396
Reaction score
189
Trophy points
1,353
Location
India
embeddedlaboratory.blogspot.in
Activity points
10,591
Hello!! Everyone i am working on LPC1343 Micro-controller and wants to interface RTCC PCF8523 with LPC1343.

I write code for I2C protocol but its not working.
The problem is found when i send repeated start from master (LPC1343), the status for this must be 0x10 while i am getting 0x28 every time.

I am attaching my code in the zip file available below.
View attachment PCF8523_RTCC.zip

The functions used for I2C Protocol are as follow:-


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include "LPC13xx.h"
#include "I2C.h"
#include "UART.h"
 
void I2C_Init(unsigned char Mode)
{   
    LPC_SYSCON->PRESETCTRL |= (1<<1);           //De-Asserts Reset Signal to I2C 
    LPC_SYSCON->SYSAHBCLKCTRL |= (1<<5);    //Enable I2C Clock
    
    LPC_IOCON->PIO0_4 &= ~0x3F;
    LPC_IOCON->PIO0_4 |= 0x01;  //SCL
    
    LPC_IOCON->PIO0_5 &= ~0x3F;
    LPC_IOCON->PIO0_5 |= 0x01;  //SDA
    
    if(Mode == I2C_SPEED_400)
    {
        LPC_I2C->SCLH = 90;         //I2PCLK is 72MHz
        LPC_I2C->SCLL = 90;         //I2PCLK is 72MHz
    }
    else if(Mode == I2C_SPEED_100)
    {
        LPC_I2C->SCLH = 360;        //I2PCLK is 72MHz
        LPC_I2C->SCLL = 360;        //I2PCLK is 72MHz
    }
    
    LPC_I2C->CONCLR = 0xFF;     //Clear All Flags   
    LPC_I2C->CONSET = (1<<6);   //I2C Interface Enable
}
void I2C_Start(void)
{
    LPC_I2C->CONSET |= 0x20;            //Set the Start Bit
    while(LPC_I2C->STAT!=0x08);     //Wait for the Status Bit
}
void I2C_Restart(void)
{
    LPC_I2C->CONSET |= 0x20;            //Set the Start Bit
    while(LPC_I2C->STAT!=0x10);     //Wait for the Status Bit
}
void I2C_Stop(void)
{
    LPC_I2C->CONSET |= 0x14;    //Stop I2C
    LPC_I2C->CONCLR = 0x08;
}
void I2C_Write(unsigned char data,unsigned char status)
{
    LPC_I2C->DAT = data;  
  LPC_I2C->CONCLR = 0X28;                       //Clear Start Flag and SI Interrupt 
  while(LPC_I2C->STAT!=status);       //Wait for the Status Byte    
}
unsigned char I2C_Read(void)
{   
  LPC_I2C->CONCLR = 0X28;
  while (LPC_I2C->STAT!=0x50);          //Wait for Status Set - 0x50
  return(LPC_I2C->DAT);
}



In function Read from RTCC (given below)


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
unsigned char PCF8523_Read(unsigned char Address)
{
    unsigned char temp;
    I2C_Start();
    UART_Write('1');
    I2C_Write(PC8523_ADDRESS,0x18);
    UART_Write('2');
    I2C_Write(Address,0x28);
    UART_Write('3');
    I2C_Restart();
    UART_Write('4');
    I2C_Write(PC8523_ADDRESS+1,0x40);
    UART_Write('5');
    temp = I2C_Read();
    UART_Write('6');
    I2C_Stop();
    UART_Write('7');
    return temp;
}



As i dont have debugger i checked the content of Status Bytes on UART, i found that for I2c_Start, the status byte contains 0x08 when sending rtcc address i am getting status = 0x18 and then after sending the address from where i have to read i am getting status = 0x28 which is correct.
Upto this point i am getting valid status responses, but after sending Repeated Start i am getting 0x28 each and every time continuously.
Can anyone please help me to solve this issue.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top