CryptoAuthLib
Atmel CryptoAuthentication Library
i2c_bitbang_at88ck9000.c File Reference

Hardware Interface Functions - I2C bit-banged. More...

#include <asf.h>
#include <stdint.h>
#include "i2c_bitbang_at88ck9000.h"

Functions

void i2c_set_pin (uint32_t sda, uint32_t scl)
 Set I2C data and clock pin. Other functions will use these pins. More...
 
void i2c_enable (void)
 Configure GPIO pins for I2C clock and data as output. More...
 
void i2c_disable (void)
 Configure GPIO pins for I2C clock and data as input. More...
 
void i2c_send_start (void)
 Send a START condition. More...
 
void i2c_send_ack (uint8_t ack)
 Send an ACK or NACK (after receive). More...
 
void i2c_send_stop (void)
 Send a STOP condition. More...
 
void i2c_send_wake_token (void)
 Send a Wake Token. More...
 
ATCA_STATUS i2c_send_byte (uint8_t i2c_byte)
 Send one byte. More...
 
ATCA_STATUS i2c_send_bytes (uint8_t count, uint8_t *data)
 Send a number of bytes. More...
 
uint8_t i2c_receive_one_byte (uint8_t ack)
 Receive one byte (MSB first). More...
 
void i2c_receive_byte (uint8_t *data)
 Receive one byte and send ACK. More...
 
void i2c_receive_bytes (uint8_t count, uint8_t *data)
 Receive a number of bytes. More...
 

Variables

I2CBuses i2c_buses_default
 
uint32_t pin_sda
 
uint32_t pin_scl
 

Detailed Description

Hardware Interface Functions - I2C bit-banged.

Author
Atmel Crypto Group
Date
November 18, 2015

Function Documentation

void i2c_disable ( void  )

Configure GPIO pins for I2C clock and data as input.

void i2c_enable ( void  )

Configure GPIO pins for I2C clock and data as output.

void i2c_receive_byte ( uint8_t *  data)

Receive one byte and send ACK.

Parameters
[out]datapointer to received byte
void i2c_receive_bytes ( uint8_t  count,
uint8_t *  data 
)

Receive a number of bytes.

Parameters
[out]datapointer to receive buffer
[in]countnumber of bytes to receive
uint8_t i2c_receive_one_byte ( uint8_t  ack)

Receive one byte (MSB first).

Parameters
[in]ack0:NACK, else:ACK
Returns
byte received

We don't need to delay after the last bit because it takes time to switch the pin to output for acknowledging.

void i2c_send_ack ( uint8_t  ack)

Send an ACK or NACK (after receive).

Parameters
[in]ack0: NACK, else: ACK

< Low data line indicates an ACK.

< High data line indicates a NACK.

Clock out acknowledgment.

ATCA_STATUS i2c_send_byte ( uint8_t  i2c_byte)

Send one byte.

Parameters
[in]i2c_bytebyte to write
Returns
ATCA_STATUS

This avoids spikes but adds an if condition. We could parametrize the call to I2C_SET_OUTPUT and translate the msb to OUTSET or OUTCLR, but then the code would become target specific.

Send 8 bits of data.

Clock out the data bit.

Shifting while clock is high compensates for the time it takes to evaluate the bit while clock is low. That way, the low and high time of the clock pin is almost equal.

Clock in last data bit.

Set data line to be an input.

Wait for the ack.

ATCA_STATUS i2c_send_bytes ( uint8_t  count,
uint8_t *  data 
)

Send a number of bytes.

Parameters
[in]countnumber of bytes to send
[in]datapointer to buffer containing bytes to send
Returns
ATCA_STATUS
void i2c_send_start ( void  )

Send a START condition.

Set clock high in case we re-start.

void i2c_send_stop ( void  )

Send a STOP condition.

void i2c_send_wake_token ( void  )

Send a Wake Token.

void i2c_set_pin ( uint32_t  sda,
uint32_t  scl 
)

Set I2C data and clock pin. Other functions will use these pins.

Parameters
[in]sdadefinition of GPIO pin to be used as data pin
[in]scldefinition of GPIO pin to be used as clock pin

Variable Documentation

I2CBuses i2c_buses_default
Initial value:
= {
{ SDA0, SDA1, SDA2, SDA3, SDA4, SDA5, SDA6, SDA7, SDA8, SDA9, SDA_ONBOARD_1 },
{ SCL0, SCL1, SCL2, SCL3, SCL4, SCL5, SCL6, SCL7, SCL8, SCL9, SCL_ONBOARD_1 }
}
uint32_t pin_scl
uint32_t pin_sda