Hanna
Sourcecode Batteriemanagementsystem
Datenstrukturen | Makrodefinitionen | Typdefinitionen | Aufzählungen | Funktionen
twi_master_driver.h-Dateireferenz

XMEGA TWI master driver header file. Mehr ...

#include <stdbool.h>
#include <stdio.h>
#include <util/delay.h>
#include <avr/io.h>
Include-Abhängigkeitsdiagramm für twi_master_driver.h:
Dieser Graph zeigt, welche Datei direkt oder indirekt diese Datei enthält:

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 ...
 

Ausführliche Beschreibung

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.

Application note:
AVR1308: Using the XMEGA TWI
Documentation
For comprehensive code documentation, supported compilers, compiler settings and supported devices see readme.html
Autor
Atmel Corporation: http://www.atmel.com
Support email: avr@a.nosp@m.tmel.nosp@m..com
Revision
351
Date
2016-03-19 23:27:55 +0100 (Sa, 19 Mrz 2016)


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:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  3. The name of ATMEL may not be used to endorse or promote products derived from this software without specific prior written permission.

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.

Makro-Dokumentation

#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.

Dokumentation der benutzerdefinierten Typen

typedef struct TWI_Master TWI_Master_t

TWI master driver struct.

TWI master struct. Holds pointer to TWI module, buffers and necessary varibles.

Transaction result enumeration.

Dokumentation der Aufzählungstypen

Transaction result enumeration.

Definiert in Zeile 89 der Datei twi_master_driver.h.

Dokumentation der Funktionen

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.

Parameter
twiThe TWI_Master_t struct instance.

Definiert in Zeile 306 der Datei twi_master_driver.c.

Hier ist ein Graph der zeigt, wo diese Funktion aufgerufen wird:

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.

Parameter
twiThe TWI_Master_t struct instance.
moduleThe TWI module to use.
intLevelMaster interrupt level.
baudRateRegisterSettingThe baud rate register value.

Definiert in Zeile 103 der Datei twi_master_driver.c.

Hier ist ein Graph der zeigt, wo diese Funktion aufgerufen wird:

void TWI_MasterInterruptHandler ( TWI_Master_t twi)

Common TWI master interrupt service routine.

Check current status and calls the appropriate handler.

Parameter
twiThe TWI_Master_t struct instance.

Definiert in Zeile 268 der Datei twi_master_driver.c.

Hier ist ein Graph, der zeigt, was diese Funktion aufruft:

Hier ist ein Graph der zeigt, wo diese Funktion aufgerufen wird:

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.

Parameter
twiThe TWI_Master_t struct instance.
addressThe slave address.
bytesToReadThe number of bytes to read.
Rückgabewerte
trueIf transaction could be started.
falseIf transaction could not be started.

Definiert in Zeile 178 der Datei twi_master_driver.c.

Hier ist ein Graph, der zeigt, was diese Funktion aufruft:

Hier ist ein Graph der zeigt, wo diese Funktion aufgerufen wird:

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.

Parameter
twiThe TWI_Master_t struct instance.

Definiert in Zeile 380 der Datei twi_master_driver.c.

Hier ist ein Graph, der zeigt, was diese Funktion aufruft:

Hier ist ein Graph der zeigt, wo diese Funktion aufgerufen wird:

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.

Parameter
twiThe TWI_Master_t struct instance.
Rückgabewerte
trueIf transaction could be started.
falseIf 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.

Parameter
twiThe TWI_Master_t struct instance.
Rückgabewerte
TWI_MASTER_BUSSTATE_UNKNOWN_gcBus state is unknown.
TWI_MASTER_BUSSTATE_IDLE_gcBus state is idle.
TWI_MASTER_BUSSTATE_OWNER_gcBus state is owned by the master.
TWI_MASTER_BUSSTATE_BUSY_gcBus 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.

Parameter
twiThe TWI_Master_t struct instance.
resultThe result of the operation.

Definiert in Zeile 421 der Datei twi_master_driver.c.

Hier ist ein Graph der zeigt, wo diese Funktion aufgerufen wird:

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.

Parameter
twiThe TWI_Master_t struct instance.
addressSlave address.
writeDataPointer to data to write.
bytesToWriteNumber of data bytes to write.
Rückgabewerte
trueIf transaction could be started.
falseIf transaction could not be started.

Definiert in Zeile 158 der Datei twi_master_driver.c.

Hier ist ein Graph, der zeigt, was diese Funktion aufruft:

Hier ist ein Graph der zeigt, wo diese Funktion aufgerufen wird:

void TWI_MasterWriteHandler ( TWI_Master_t twi)

TWI master write interrupt handler.

Handles TWI transactions (master write) and responses to (N)ACK.

Parameter
twiThe TWI_Master_t struct instance.

Definiert in Zeile 333 der Datei twi_master_driver.c.

Hier ist ein Graph, der zeigt, was diese Funktion aufruft:

Hier ist ein Graph der zeigt, wo diese Funktion aufgerufen wird:

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.

Parameter
twiThe TWI_Master_t struct instance.
addressThe slave address.
writeDataPointer to data to write.
bytesToWriteNumber of bytes to write.
bytesToReadNumber of bytes to read.
Rückgabewerte
trueIf transaction could be started.
falseIf transaction could not be started.

Definiert in Zeile 202 der Datei twi_master_driver.c.

Hier ist ein Graph der zeigt, wo diese Funktion aufgerufen wird: