Hanna
Sourcecode Batteriemanagementsystem |
XMEGA TWI master driver source file. Mehr ...
#include <stdbool.h>
#include <stdio.h>
#include <avr/io.h>
#include "twi_master_driver.h"
#include <util/delay.h>
gehe zum Quellcode dieser Datei
Makrodefinitionen | |
#define | F_CPU 32000000 |
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 source file.
This file contains the function implementations the XMEGA master TWI 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.
Several functions use the following construct: "some_register = ... | (some_parameter ? SOME_BIT_bm : 0) | ..." Although the use of the ternary operator ( if ? then : else ) is discouraged, in some occasions the operator makes it possible to write pretty clean and neat code. In this driver, the construct is used to set or not set a configuration bit based on a boolean input parameter, such as the "some_parameter" in the example above.
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.c.
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.