Defines | Enumerations | Functions

usiTwiSlave.c File Reference

#include <avr/io.h>
#include <avr/interrupt.h>
#include "usiTwiSlave.h"

Go to the source code of this file.

Defines

#define SET_USI_TO_SEND_ACK()
#define SET_USI_TO_READ_ACK()
#define SET_USI_TO_TWI_START_CONDITION_MODE()
#define SET_USI_TO_SEND_DATA()
#define SET_USI_TO_READ_DATA()

Enumerations

enum  overflowState_t {
  USI_SLAVE_CHECK_ADDRESS = 0x00, USI_SLAVE_SEND_DATA = 0x01, USI_SLAVE_REQUEST_REPLY_FROM_SEND_DATA = 0x02, USI_SLAVE_CHECK_REPLY_FROM_SEND_DATA = 0x03,
  USI_SLAVE_REQUEST_DATA = 0x04, USI_SLAVE_GET_DATA_AND_SEND_ACK = 0x05
}

Functions

void usiTwiSlaveInit (uint8_t ownAddress)
void usiTwiTransmitByte (uint8_t data)
uint8_t usiTwiReceiveByte (void)
bool usiTwiDataInReceiveBuffer (void)
 ISR (USI_START_VECTOR)
 ISR (USI_OVERFLOW_VECTOR)

Define Documentation

#define SET_USI_TO_READ_ACK (  )
Value:
{ \
  /* set SDA as input */ \
  DDR_USI &= ~( 1 << PORT_USI_SDA ); \
  /* prepare ACK */ \
  USIDR = 0; \
  /* clear all interrupt flags, except Start Cond */ \
  USISR = \
       ( 0 << USI_START_COND_INT ) | \
       ( 1 << USIOIF ) | \
       ( 1 << USIPF ) | \
       ( 1 << USIDC ) | \
       /* set USI counter to shift 1 bit */ \
       ( 0x0E << USICNT0 ); \
}

Definition at line 165 of file usiTwiSlave.c.

Referenced by ISR().

#define SET_USI_TO_READ_DATA (  )
Value:
{ \
  /* set SDA as input */ \
  DDR_USI &= ~( 1 << PORT_USI_SDA ); \
  /* clear all interrupt flags, except Start Cond */ \
  USISR    = \
       ( 0 << USI_START_COND_INT ) | ( 1 << USIOIF ) | \
       ( 1 << USIPF ) | ( 1 << USIDC ) | \
       /* set USI to shift out 8 bits */ \
       ( 0x0 << USICNT0 ); \
}

Definition at line 211 of file usiTwiSlave.c.

Referenced by ISR().

#define SET_USI_TO_SEND_ACK (  )
Value:
{ \
  /* prepare ACK */ \
  USIDR = 0; \
  /* set SDA as output */ \
  DDR_USI |= ( 1 << PORT_USI_SDA ); \
  /* clear all interrupt flags, except Start Cond */ \
  USISR = \
       ( 0 << USI_START_COND_INT ) | \
       ( 1 << USIOIF ) | ( 1 << USIPF ) | \
       ( 1 << USIDC )| \
       /* set USI counter to shift 1 bit */ \
       ( 0x0E << USICNT0 ); \
}

Definition at line 150 of file usiTwiSlave.c.

Referenced by ISR().

#define SET_USI_TO_SEND_DATA (  )
Value:
{ \
  /* set SDA as output */ \
  DDR_USI |=  ( 1 << PORT_USI_SDA ); \
  /* clear all interrupt flags, except Start Cond */ \
  USISR    =  \
       ( 0 << USI_START_COND_INT ) | ( 1 << USIOIF ) | ( 1 << USIPF ) | \
       ( 1 << USIDC) | \
       /* set USI to shift out 8 bits */ \
       ( 0x0 << USICNT0 ); \
}

Definition at line 199 of file usiTwiSlave.c.

Referenced by ISR().

#define SET_USI_TO_TWI_START_CONDITION_MODE (  )
Value:
{ \
  USICR = \
       /* enable Start Condition Interrupt, disable Overflow Interrupt */ \
       ( 1 << USISIE ) | ( 0 << USIOIE ) | \
       /* set USI in Two-wire mode, no USI Counter overflow hold */ \
       ( 1 << USIWM1 ) | ( 0 << USIWM0 ) | \
       /* Shift Register Clock Source = External, positive edge */ \
       /* 4-Bit Counter Source = external, both edges */ \
       ( 1 << USICS1 ) | ( 0 << USICS0 ) | ( 0 << USICLK ) | \
       /* no toggle clock-port pin */ \
       ( 0 << USITC ); \
  USISR = \
        /* clear all interrupt flags, except Start Cond */ \
        ( 0 << USI_START_COND_INT ) | ( 1 << USIOIF ) | ( 1 << USIPF ) | \
        ( 1 << USIDC ) | ( 0x0 << USICNT0 ); \
}

Definition at line 181 of file usiTwiSlave.c.

Referenced by ISR().


Enumeration Type Documentation

Enumerator:
USI_SLAVE_CHECK_ADDRESS 
USI_SLAVE_SEND_DATA 
USI_SLAVE_REQUEST_REPLY_FROM_SEND_DATA 
USI_SLAVE_CHECK_REPLY_FROM_SEND_DATA 
USI_SLAVE_REQUEST_DATA 
USI_SLAVE_GET_DATA_AND_SEND_ACK 

Definition at line 231 of file usiTwiSlave.c.


Function Documentation

ISR ( USI_OVERFLOW_VECTOR   )
ISR ( USI_START_VECTOR   )

Definition at line 413 of file usiTwiSlave.c.

References USI_SLAVE_CHECK_ADDRESS.

bool usiTwiDataInReceiveBuffer ( void   )

Definition at line 395 of file usiTwiSlave.c.

Referenced by evaluate_i2c_input().

uint8_t usiTwiReceiveByte ( void   )

Definition at line 374 of file usiTwiSlave.c.

References TWI_RX_BUFFER_MASK.

Referenced by evaluate_i2c_input().

void usiTwiSlaveInit ( uint8_t  ownAddress )

Definition at line 298 of file usiTwiSlave.c.

Referenced by main().

void usiTwiTransmitByte ( uint8_t  data )

Definition at line 348 of file usiTwiSlave.c.

References TWI_TX_BUFFER_MASK.