This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Problem reading DS1307

Hi,

I am using the DS1307 library for STM32L152. The original library for STM32F429 is at here:
stm32f4-discovery.com/.../

It seems a complete library however after few modification to STM32L I cant read/write DS1307.
what ever is received is 1.


int main(void)
{
        TM_DS1307_Time_t tim;
        SystemCoreClockSetHSI();
        GPIO_RCC_configuration();
        GPIO_configuration();
        Init_SPI();
        uart1_configuration();
        I2C2_init();
        TIM4_configuration();

        TM_DS1307_SetDateTime(&tim);
        while(1)
        {

                tim.seconds=TM_DS1307_GetSeconds();
                sprintf(str," \r\ns=%u",tim.seconds);
                uart_out_str(str);
                delay_ms(1000);
        }
}


result is

s=1
s=1
s=1
s=1
s=1
s=1


I see signals in scope and there is a delay about 200ms when reading from DS1307 (reading timeout). when I debug, DR changes between 0xD0 and 0xD1. How can I find where the problem is?

Parents
  • I found another library which is a little smaller in size. It is written for STM32F0 but I try to understand below function, is there a way to transfer it to STM32L1XX?

    void I2C_TransferHandling(
    I2C_TypeDef *   I2Cx,
    uint16_t        Address,
    uint8_t         Number_Bytes,
    uint32_t        ReloadEndMode,
    uint32_t        StartStopMode
    )
    

    Is there equivalent in STM32L1xx?

          void I2C_WrReg(uint8_t Reg, uint8_t Dat){
            while(I2C_GetFlagStatus(DS_I2C, I2C_FLAG_BUSY) == SET);
    
            I2C_TransferHandling(DS_I2C, DS_ADDR, 1, I2C_Reload_Mode, I2C_Generate_Start_Write);
            while(I2C_GetFlagStatus(DS_I2C, I2C_FLAG_TXIS) == RESET);
    
            I2C_SendData(DS_I2C, Reg);
            while(I2C_GetFlagStatus(DS_I2C, I2C_FLAG_TCR) == RESET);
    
            I2C_TransferHandling(DS_I2C, DS_ADDR, 1, I2C_AutoEnd_Mode, I2C_No_StartStop);
            while(I2C_GetFlagStatus(DS_I2C, I2C_FLAG_TXIS) == RESET);
    
            I2C_SendData(DS_I2C, Dat);
            while(I2C_GetFlagStatus(DS_I2C, I2C_FLAG_STOPF) == RESET);
            I2C_ClearFlag(DS_I2C, I2C_FLAG_STOPF);
    }
    
    

Reply
  • I found another library which is a little smaller in size. It is written for STM32F0 but I try to understand below function, is there a way to transfer it to STM32L1XX?

    void I2C_TransferHandling(
    I2C_TypeDef *   I2Cx,
    uint16_t        Address,
    uint8_t         Number_Bytes,
    uint32_t        ReloadEndMode,
    uint32_t        StartStopMode
    )
    

    Is there equivalent in STM32L1xx?

          void I2C_WrReg(uint8_t Reg, uint8_t Dat){
            while(I2C_GetFlagStatus(DS_I2C, I2C_FLAG_BUSY) == SET);
    
            I2C_TransferHandling(DS_I2C, DS_ADDR, 1, I2C_Reload_Mode, I2C_Generate_Start_Write);
            while(I2C_GetFlagStatus(DS_I2C, I2C_FLAG_TXIS) == RESET);
    
            I2C_SendData(DS_I2C, Reg);
            while(I2C_GetFlagStatus(DS_I2C, I2C_FLAG_TCR) == RESET);
    
            I2C_TransferHandling(DS_I2C, DS_ADDR, 1, I2C_AutoEnd_Mode, I2C_No_StartStop);
            while(I2C_GetFlagStatus(DS_I2C, I2C_FLAG_TXIS) == RESET);
    
            I2C_SendData(DS_I2C, Dat);
            while(I2C_GetFlagStatus(DS_I2C, I2C_FLAG_STOPF) == RESET);
            I2C_ClearFlag(DS_I2C, I2C_FLAG_STOPF);
    }
    
    

Children
No data