Hanna
Sourcecode Batteriemanagementsystem |
XMEGA TWI master driver header file. Mehr ...
#include <stdbool.h>
#include <stdio.h>
#include <util/delay.h>
#include <avr/io.h>
gehe zum Quellcode dieser Datei
Datenstrukturen | |
struct | TWI_Master |
TWI master driver struct. Mehr ... | |
Makrodefinitionen | |
#define | TWI_BAUD(F_SYS, F_TWI) ((F_SYS / (2 * F_TWI)) - 5) |
#define | TWIM_READ_BUFFER_SIZE 16 |
#define | TWIM_STATUS_BUSY 1 |
#define | TWIM_STATUS_READY 0 |
#define | TWIM_WRITE_BUFFER_SIZE 8 |
Typdefinitionen | |
typedef struct TWI_Master | TWI_Master_t |
TWI master driver struct. Mehr ... | |
typedef enum TWIM_RESULT_enum | TWIM_RESULT_t |
Aufzählungen | |
enum | TWIM_RESULT_enum { TWIM_RESULT_UNKNOWN = (0x00 << 0), TWIM_RESULT_OK = (0x01 << 0), TWIM_RESULT_BUFFER_OVERFLOW = (0x02 << 0), TWIM_RESULT_ARBITRATION_LOST = (0x03 << 0), TWIM_RESULT_BUS_ERROR = (0x04 << 0), TWIM_RESULT_NACK_RECEIVED = (0x05 << 0), TWIM_RESULT_FAIL = (0x06 << 0) } |
Funktionen | |
void | TWI_MasterArbitrationLostBusErrorHandler (TWI_Master_t *twi) |
TWI master arbitration lost and bus error interrupt handler. Mehr ... | |
void | TWI_MasterInit (TWI_Master_t *twi, TWI_t *module, TWI_MASTER_INTLVL_t intLevel, uint8_t baudRateRegisterSetting) |
Initialise the TWI module. Mehr ... | |
void | TWI_MasterInterruptHandler (TWI_Master_t *twi) |
Common TWI master interrupt service routine. Mehr ... | |
bool | TWI_MasterRead (TWI_Master_t *twi, uint8_t address, uint8_t bytesToRead) |
TWI read transaction. Mehr ... | |
void | TWI_MasterReadHandler (TWI_Master_t *twi) |
TWI master read interrupt handler. Mehr ... | |
bool | TWI_MasterReady (TWI_Master_t *twi) |
Returns true if transaction is ready. Mehr ... | |
TWI_MASTER_BUSSTATE_t | TWI_MasterState (TWI_Master_t *twi) |
Returns the TWI bus state. Mehr ... | |
void | TWI_MasterTransactionFinished (TWI_Master_t *twi, uint8_t result) |
TWI transaction finished handler. Mehr ... | |
bool | TWI_MasterWrite (TWI_Master_t *twi, uint8_t address, uint8_t *writeData, uint8_t bytesToWrite) |
TWI write transaction. Mehr ... | |
void | TWI_MasterWriteHandler (TWI_Master_t *twi) |
TWI master write interrupt handler. Mehr ... | |
bool | TWI_MasterWriteRead (TWI_Master_t *twi, uint8_t address, uint8_t *writeData, uint8_t bytesToWrite, uint8_t bytesToRead) |
TWI write and/or read transaction. Mehr ... | |
XMEGA TWI master driver header file.
This file contains the function prototypes and enumerator definitions for various configuration parameters for the XMEGA TWI master driver.
The driver is not intended for size and/or speed critical code, since most functions are just a few lines of code, and the function call overhead would decrease code performance. The driver is intended for rapid prototyping and documentation purposes for getting started with the XMEGA TWI master module.
For size and/or speed critical code, it is recommended to copy the function contents directly into your application instead of making a function call.
Copyright (c) 2008, Atmel Corporation All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Definiert in Datei twi_master_driver.h.
#define TWI_BAUD | ( | F_SYS, | |
F_TWI | |||
) | ((F_SYS / (2 * F_TWI)) - 5) |
Baud register setting calculation. Formula described in datasheet.
Definiert in Zeile 82 der Datei twi_master_driver.h.
#define TWIM_STATUS_READY 0 |
Transaction status defines.
Definiert in Zeile 85 der Datei twi_master_driver.h.
#define TWIM_WRITE_BUFFER_SIZE 8 |
Buffer size defines
Definiert in Zeile 95 der Datei twi_master_driver.h.
typedef struct TWI_Master TWI_Master_t |
TWI master driver struct.
TWI master struct. Holds pointer to TWI module, buffers and necessary varibles.
typedef enum TWIM_RESULT_enum TWIM_RESULT_t |
Transaction result enumeration.
enum TWIM_RESULT_enum |
Transaction result enumeration.
Definiert in Zeile 89 der Datei twi_master_driver.h.
void TWI_MasterArbitrationLostBusErrorHandler | ( | TWI_Master_t * | twi | ) |
TWI master arbitration lost and bus error interrupt handler.
Handles TWI responses to lost arbitration and bus error.
twi | The TWI_Master_t struct instance. |
Definiert in Zeile 306 der Datei twi_master_driver.c.
void TWI_MasterInit | ( | TWI_Master_t * | twi, |
TWI_t * | module, | ||
TWI_MASTER_INTLVL_t | intLevel, | ||
uint8_t | baudRateRegisterSetting | ||
) |
Initialise the TWI module.
TWI module initialisation function. Enables master read and write interrupts. Remember to enable interrupts globally from the main application.
twi | The TWI_Master_t struct instance. |
module | The TWI module to use. |
intLevel | Master interrupt level. |
baudRateRegisterSetting | The baud rate register value. |
Definiert in Zeile 103 der Datei twi_master_driver.c.
void TWI_MasterInterruptHandler | ( | TWI_Master_t * | twi | ) |
Common TWI master interrupt service routine.
Check current status and calls the appropriate handler.
twi | The TWI_Master_t struct instance. |
Definiert in Zeile 268 der Datei twi_master_driver.c.
bool TWI_MasterRead | ( | TWI_Master_t * | twi, |
uint8_t | address, | ||
uint8_t | bytesToRead | ||
) |
TWI read transaction.
This function is a TWI Maste wrapper for read-only transaction.
twi | The TWI_Master_t struct instance. |
address | The slave address. |
bytesToRead | The number of bytes to read. |
true | If transaction could be started. |
false | If transaction could not be started. |
Definiert in Zeile 178 der Datei twi_master_driver.c.
void TWI_MasterReadHandler | ( | TWI_Master_t * | twi | ) |
TWI master read interrupt handler.
This is the master read interrupt handler that takes care of reading bytes from the TWI slave.
twi | The TWI_Master_t struct instance. |
Definiert in Zeile 380 der Datei twi_master_driver.c.
bool TWI_MasterReady | ( | TWI_Master_t * | twi | ) |
Returns true if transaction is ready.
This function returns a boolean whether the TWI Master is ready for a new transaction.
twi | The TWI_Master_t struct instance. |
true | If transaction could be started. |
false | If transaction could not be started. |
Definiert in Zeile 140 der Datei twi_master_driver.c.
TWI_MASTER_BUSSTATE_t TWI_MasterState | ( | TWI_Master_t * | twi | ) |
Returns the TWI bus state.
Returns the TWI bus state (type defined in device headerfile), unknown, idle, owner or busy.
twi | The TWI_Master_t struct instance. |
TWI_MASTER_BUSSTATE_UNKNOWN_gc | Bus state is unknown. |
TWI_MASTER_BUSSTATE_IDLE_gc | Bus state is idle. |
TWI_MASTER_BUSSTATE_OWNER_gc | Bus state is owned by the master. |
TWI_MASTER_BUSSTATE_BUSY_gc | Bus state is busy. |
Definiert in Zeile 123 der Datei twi_master_driver.c.
void TWI_MasterTransactionFinished | ( | TWI_Master_t * | twi, |
uint8_t | result | ||
) |
TWI transaction finished handler.
Prepares module for new transaction.
twi | The TWI_Master_t struct instance. |
result | The result of the operation. |
Definiert in Zeile 421 der Datei twi_master_driver.c.
bool TWI_MasterWrite | ( | TWI_Master_t * | twi, |
uint8_t | address, | ||
uint8_t * | writeData, | ||
uint8_t | bytesToWrite | ||
) |
TWI write transaction.
This function is TWI Master wrapper for a write-only transaction.
twi | The TWI_Master_t struct instance. |
address | Slave address. |
writeData | Pointer to data to write. |
bytesToWrite | Number of data bytes to write. |
true | If transaction could be started. |
false | If transaction could not be started. |
Definiert in Zeile 158 der Datei twi_master_driver.c.
void TWI_MasterWriteHandler | ( | TWI_Master_t * | twi | ) |
TWI master write interrupt handler.
Handles TWI transactions (master write) and responses to (N)ACK.
twi | The TWI_Master_t struct instance. |
Definiert in Zeile 333 der Datei twi_master_driver.c.
bool TWI_MasterWriteRead | ( | TWI_Master_t * | twi, |
uint8_t | address, | ||
uint8_t * | writeData, | ||
uint8_t | bytesToWrite, | ||
uint8_t | bytesToRead | ||
) |
TWI write and/or read transaction.
This function is a TWI Master write and/or read transaction. The function can be used to both write and/or read bytes to/from the TWI Slave in one transaction.
twi | The TWI_Master_t struct instance. |
address | The slave address. |
writeData | Pointer to data to write. |
bytesToWrite | Number of bytes to write. |
bytesToRead | Number of bytes to read. |
true | If transaction could be started. |
false | If transaction could not be started. |
Definiert in Zeile 202 der Datei twi_master_driver.c.