hi
i connect ds1307 like this
battery is 3V and voltage on VCC is 5V . i connect another i2c device to i2c bus that its name is 24cxx
24cxx vcc is 3.3 V . because its all open drain so i dont think it would be a problem to connect5 both of them to lpc1768
on keil for lpc1768 i connect to 24cxx and everything work right but when i try to connect to ds1307 its not happening
this is my code
#include "DS1307.h"
#include "Driver_I2C.h"
#include <string.h>
#include "cmsis_os.h" // ARM::CMSIS:RTOS:Keil RTX
/* I2C Driver */
extern ARM_DRIVER_I2C Driver_I2C0;
static ARM_DRIVER_I2C * DS1307I2Cdrv = &Driver_I2C0;
#define DS1307_I2C_ADDR 0xD0 /* DS1307 I2C address */
#define A_WR 0 /* Master will write to the I2C */
#define A_RD 1 /* Master will read from the I2C */
static uint8_t DS1307DeviceAddr;
static uint8_t DS1307_wr_buf[58];
void DS1307Init(){
DS1307I2Cdrv->Initialize (NULL);
DS1307I2Cdrv->PowerControl (ARM_POWER_FULL);
DS1307I2Cdrv->Control (ARM_I2C_BUS_SPEED, ARM_I2C_BUS_SPEED_STANDARD);
DS1307I2Cdrv->Control (ARM_I2C_BUS_CLEAR, 0);
/* Init 24cxx EEPROM device */
DS1307DeviceAddr = DS1307_I2C_ADDR;
osDelay(100);
unsigned char temp[1] = {0};
DS1307_WriteBuf(0 , temp , 1);
}
int32_t DS1307_ReadBuf (uint16_t addr, uint8_t *buf, uint32_t len) {
uint8_t a[2];
a[0] = (uint8_t)(addr >> 8);
a[1] = (uint8_t)(addr & 0xFF);
DS1307I2Cdrv->MasterTransmit (DS1307DeviceAddr, a, 2, true);
while (DS1307I2Cdrv->GetStatus().busy);
DS1307I2Cdrv->MasterReceive (DS1307DeviceAddr, buf, len, false);
while (DS1307I2Cdrv->GetStatus().busy);
if (DS1307I2Cdrv->GetDataCount () != len) return -1;
return 0;
}
int32_t DS1307_WriteBuf (uint16_t addr, const uint8_t *buf, uint32_t len) {
DS1307_wr_buf[0] = (uint8_t)(addr >> 8);
DS1307_wr_buf[1] = (uint8_t)(addr & 0xFF);
memcpy (&DS1307_wr_buf[2], &buf[0], len);
DS1307I2Cdrv->MasterTransmit (DS1307DeviceAddr, DS1307_wr_buf, len + 2, false);
while (DS1307I2Cdrv->GetStatus().busy);
if (DS1307I2Cdrv->GetDataCount () != (len + 2)) return -1;
/* Acknowledge polling */
do {
DS1307I2Cdrv->MasterReceive (DS1307DeviceAddr, &DS1307_wr_buf[0], 1, false);
while (DS1307I2Cdrv->GetStatus().busy);
} while (DS1307I2Cdrv->GetDataCount () < 0);
return 0;
}
in logic analyzer i just recieve this
why i cant read or write anything to it?
its my main code
DS1307Init();
osDelay(100);
state = DS1307_ReadBuf(0,mTime,1);
Solved! Go to Solution.
Hi navid ansari,
Thanks for reply.
Firstly, I think the hardware circuit is correct, and I've attached a DS1302 driver.
Please refer to it for details.
Have a great day,
TIC
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
Hi navid ansari,
Thanks for reply.
Firstly, I think the hardware circuit is correct, and I've attached a DS1302 driver.
Please refer to it for details.
Have a great day,
TIC
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------