![]() |
Real Time Clock Module with I2C Interface
0.3
|
|
⇒ back to Project Page |
Contains the functions for the data transmission via the I2C interface as master and also as slave. More...
Go to the source code of this file.
Macros | |
| #define | I2C_SLAVE_INTERRUPT_OPERATION 1 |
| specifies operation mode of slave mode: interrupt (1) or polling (0) | |
| #define | I2C_WAIT_BEFORE_STA_US 4 |
| time to wait before START condition will be sent | |
| #define | I2C_MAX_RETRYS 3 |
| maximum number of bus arbitration retrys | |
| #define | I2C_RETRY_WAIT_US 30 |
| time to wait until next retry [us] | |
| #define | I2C_MAX_STA_WAIT_CYCLES 250 |
| maximum number of wait cycles in Bus START operation | |
| #define | I2C_STA_RETRY_WAIT_US 5 |
| time to wait until next cycle starts [us] | |
| #define | I2C_MAX_TIMEOUT_WAIT_CYCLES 250 |
| maximum number of wait cycles in Bus I/O operation | |
| #define | I2C_TIMEOUT_RETRY_WAIT_US 1 |
| time to wait until next cycle starts [us] | |
| #define | I2C_RESET_BUS_ON_ERROR 1 |
| check bus state BEFORE starting a Master Mode communication and resets Bus (switch off TWI) if Bus Error occured or TWI-Bit is set (1) or checks only the bus and returns an error if Bus Error occured (0) | |
| #define | I2C_MASTER_BUFFER_LENGTH 10 |
| length of buffer for I2C Bus communication (as master) | |
| #define | I2C_SLAVE_BUFFER_LENGTH 7 |
| buffer length of buffer for slave I/O (number of registers including address) NOT BIGGER THAN UINT8_MAX-1!! | |
| #define | I2C_SCL_FREQ 100000 |
| SCL frequency [Hz]. | |
| #define | I2C_SLAVE_ADDRESS 0xaa |
| own Slave Address for I2C Bus (7 Bit, last Bit specifies "General Call Recognition Enable") | |
| #define | I2C_MAX_PRESCALER_1 255 |
| internal prescaler value - DO NOT CHANGE! | |
| #define | I2C_MAX_PRESCALER_4 1020 |
| internal prescaler value - DO NOT CHANGE! | |
| #define | I2C_MAX_PRESCALER_16 4080 |
| internal prescaler value - DO NOT CHANGE! | |
| #define | I2C_MAX_PRESCALER_64 16320 |
| internal prescaler value - DO NOT CHANGE! | |
| #define | I2C_SCL_SET_SUCC 0 |
| setting of SCL frequency was successful | |
| #define | I2C_SCL_ERR 1 |
| requested SCL frequency not available < set frequency to max or min value | |
| #define | I2C_IO_SUCC 0xd0 |
| data transfer was successful | |
| #define | I2C_IO_NUM_ERROR 0xd1 |
| error during data i/o: wrong number of bytes | |
| #define | I2C_IO_BLOCK_ERROR 0xd2 |
| error during bus accessing (slave mode already active) | |
| #define | I2C_STA_ERROR 0xd3 |
| error during Bus START operation | |
| #define | I2C_TIMEOUT_ERROR 0xd4 |
| timeout during bus operation occured | |
| #define | I2C_IO_BUS_ERROR 0xd5 |
| error during bus I/O occured | |
| #define | I2C_IO_ERROR 0xd6 |
| I2C communication was not succesful. | |
| #define | I2C_START_COND_TRANS 0x08 |
| start condition was transmitted | |
| #define | I2C_RSTART_COND_TRANS 0x10 |
| repeated start condition was transmitted | |
| #define | I2C_SLAW_TRANS 0x18 |
| Slave Address + Write-Bit transmitted. | |
| #define | I2C_SLAR_TRANS 0x40 |
| Slave Address + Read-Bit transmitted. | |
| #define | I2C_M_NOACK_SLAW 0x20 |
| no ACK after Slave Address + Write-Bit | |
| #define | I2C_M_NOACK_SLAR 0x48 |
| no ACK after Slave Address + Read-Bit | |
| #define | I2C_DATA_TRANS 0x28 |
| Data transmitted. | |
| #define | I2C_DATA_RCV_ACK 0x50 |
| Data received and ACK sent to slave. | |
| #define | I2C_DATA_RCV_NACK 0x58 |
| Data received and NOACK sent to slave. | |
| #define | I2C_M_NOACK_DATA_SEND 0x30 |
| no ACK after sending data | |
| #define | I2C_M_ARB_LOST 0x38 |
| arbitration lost | |
| #define | I2C_BUS_ERROR 0x00 |
| Bus Error (after illegal start or stop condition) | |
| #define | I2C_SLAW_ACK_RCVD 0x60 |
| own address + Write Bit received, ACK sent | |
| #define | I2C_SLAW_ACK_ARB_LOST 0x68 |
| Arbitration lost as Master (SLAW), SLAW received, ACK sent. | |
| #define | I2C_GCA_ACK_RCVD 0x70 |
| General Call + Write Bit received, ACK sent. | |
| #define | I2C_GCA_ACK_ARB_LOST 0x78 |
| Arbitration lost as Master (SLAW), General Call+W received, ACK sent. | |
| #define | I2C_DATA_ACK_RCVD 0x80 |
| Data received, ACK sent. | |
| #define | I2C_DATA_NOACK_RCVD 0x88 |
| Data received, NOACK sent. | |
| #define | I2C_GCA_DATA_ACK_RCVD 0x90 |
| General Call Data received, ACK sent. | |
| #define | I2C_GCA_DATA_NOACK_RCVD 0x98 |
| General Call Data received, NOACK sent. | |
| #define | I2C_STO_REPSTART_COND 0xa0 |
| stop or repeated start condition received (while adressed) | |
| #define | I2C_SLAR_ACK_RCVD 0xa8 |
| own address + Read Bit received, ACK returned | |
| #define | I2C_SLAR_ACK_ARB_LOST 0xb0 |
| Arbitration lost as Master (SLAR), SLAR received, ACK returned. | |
| #define | I2C_DATA_ACK_TRANS 0xb8 |
| Data transmitted, ACK received. | |
| #define | I2C_DATA_NOACK_TRANS 0xc0 |
| Data transmitted, NOACK received. | |
| #define | I2C_LAST_DATA_ACK_TRANS 0xc8 |
| Last Data Byte transmitted, ACK received. | |
| #define | I2C_REGISTER_ERROR_VALUE 0xff |
| error value which is sent if address is invalid | |
| #define | I2C_SLAVE_MODE_CONTINUE 0 |
| continue slave mode after complete transmission | |
| #define | I2C_SLAVE_MODE_END 1 |
| switch off slave mode after complete transmission | |
| #define | I2C_SLAVE_MODE_ABORT 2 |
| switch of slave mode after during transmission (send NOACK) | |
Functions | |
| void | i2c_pin_init (void) |
| uint8_t | i2c_set_scl (uint32_t, uint32_t) |
| uint8_t | i2c_master_data_io (uint8_t *, uint8_t, uint8_t) |
| uint8_t | i2c_slave_data_io (volatile uint8_t *, volatile uint8_t *, volatile uint8_t) |
Contains the functions for the data transmission via the I2C interface as master and also as slave.
Platform: AVR ATmega (tested on ATmega168)
Include Files:
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along with this program. If not, see http://www.gnu.org/licenses/.
Definition in file i2c.h.
1.8.2