Subversion Repositories idreammicro-avr

Compare Revisions

Ignore whitespace Rev 62 → Rev 63

/trunk/libraries/ds1307/src/ds1307.c
319,3 → 319,133
twi__send_data(register_value);
twi__stop();
}
 
/**************************************************************************//**
* \fn uint8_t ds1307__read_byte_in_ram(uint8_t address)
*
* \brief Read a byte in DS1307 RAM.
*
* \param address Address to read.
*
* \return Read byte.
******************************************************************************/
uint8_t
ds1307__read_byte_in_ram
(
uint8_t address
){
// Check the preconditions.
assert(address >= 0x08);
assert(address <= 0x3F);
 
uint8_t data = 0;
 
twi__start();
twi__send_slaw(DS1307__ADDRESS);
twi__send_data(address);
twi__stop();
 
twi__start();
twi__send_slar(DS1307__ADDRESS);
twi__receive_data_nack(&data);
twi__stop();
 
return data;
}
 
/**************************************************************************//**
* \fn void ds1307__read_bytes_in_ram(
* uint8_t address,
* uint8_t length,
* uint8_t* p_data)
*
* \brief Read bytes in DS1307 RAM.
*
* \param address Address to read.
* \param length Number of bytes to read.
* \param[in] p_data Buffer to fill.
******************************************************************************/
void
ds1307__read_bytes_in_ram
(
uint8_t address,
uint8_t length,
uint8_t* p_data
){
// Check the preconditions.
assert(NULL != p_data);
assert(address >= 0x08);
assert(address <= 0x3F);
assert(length <= 56);
 
twi__start();
twi__send_slaw(DS1307__ADDRESS);
twi__send_data(address);
twi__stop();
 
twi__start();
twi__send_slar(DS1307__ADDRESS);
for (uint8_t i = 0; i < length - 1; i++)
{
twi__receive_data_ack(p_data + i);
}
twi__receive_data_nack(p_data + length - 1);
twi__stop();
}
 
/**************************************************************************//**
* \fn void ds1307__write_byte_in_ram(uint8_t address, uint8_t data)
*
* \brief Write a byte in DS1307 RAM.
*
* \param address Address to write.
* \param data Byte to write.
******************************************************************************/
void
ds1307__write_byte_in_ram
(
uint8_t address,
uint8_t data
){
// Check the preconditions.
assert(address >= 0x08);
assert(address <= 0x3F);
 
twi__start();
twi__send_slaw(DS1307__ADDRESS);
twi__send_data(address);
twi__send_data(data);
twi__stop();
}
 
/**************************************************************************//**
* \fn void ds1307__write_bytes_in_ram(uint8_t address, uint8_t data)
*
* \brief Write a byte in DS1307 RAM.
*
* \param address Address to write.
* \param length Number of bytes to write.
* \param[in] p_data Bytes to write.
******************************************************************************/
void
ds1307__write_bytes_in_ram
(
uint8_t address,
uint8_t length,
uint8_t* p_data
){
// Check the preconditions.
assert(NULL != p_data);
assert(address >= 0x08);
assert(address <= 0x3F);
assert(length <= 56);
 
twi__start();
twi__send_slaw(DS1307__ADDRESS);
twi__send_data(address);
for (uint8_t i = 0; i < length; i++)
{
twi__send_data(p_data[i]);
}
twi__stop();
}