SAM3S8/SD8 Software Package: libraries/libchip_sam3s/include/twi.h File Reference

SAM3S8/SD8 Software Package 1.2
Defines | Functions

# twi.h File Reference

`#include "chip.h"`
`#include <stdint.h>`

Go to the source code of this file.

## Defines

#define | TWI_STATUS_TXRDY(status) ((status & TWI_SR_TXRDY) == TWI_SR_TXRDY)
#define | TWI_STATUS_RXRDY(status) ((status & TWI_SR_RXRDY) == TWI_SR_RXRDY)
#define | TWI_STATUS_TXCOMP(status) ((status & TWI_SR_TXCOMP) == TWI_SR_TXCOMP)

## Functions

void | TWI_ConfigureMaster (Twi *pTwi, uint32_t twck, uint32_t mck)
| Configures a TWI peripheral to operate in master mode, at the given frequency (in Hz). The duty cycle of the TWI clock is set to 50%.
void | TWI_ConfigureSlave (Twi *pTwi, uint8_t slaveAddress)
| Configures a TWI peripheral to operate in slave mode.
void | TWI_Stop (Twi *pTwi)
| Sends a STOP condition on the TWI.
void | TWI_StartRead (Twi *pTwi, uint8_t address, uint32_t iaddress, uint8_t isize)
| Starts a read operation on the TWI bus with the specified slave, it returns immediately. Data must then be read using TWI_ReadByte() whenever a byte is available (poll using TWI_ByteReceived()).
uint8_t | TWI_ReadByte (Twi *pTwi)
| Reads a byte from the TWI bus. The read operation must have been started using TWI_StartRead() and a byte must be available (check with TWI_ByteReceived()).
void | TWI_WriteByte (Twi *pTwi, uint8_t byte)
| Sends a byte of data to one of the TWI slaves on the bus.
void | TWI_StartWrite (Twi *pTwi, uint8_t address, uint32_t iaddress, uint8_t isize, uint8_t byte)
| Starts a write operation on the TWI to access the selected slave, then returns immediately. A byte of data must be provided to start the write; other bytes are written next. after that to send the remaining bytes.
uint8_t | TWI_ByteReceived (Twi *pTwi)
| Check if a byte have been receiced from TWI.
uint8_t | TWI_ByteSent (Twi *pTwi)
| Check if a byte have been sent to TWI.
uint8_t | TWI_TransferComplete (Twi *pTwi)
| Check if current transmission is complet.
void | TWI_EnableIt (Twi *pTwi, uint32_t sources)
| Enables the selected interrupts sources on a TWI peripheral.
void | TWI_DisableIt (Twi *pTwi, uint32_t sources)
| Disables the selected interrupts sources on a TWI peripheral.
uint32_t | TWI_GetStatus (Twi *pTwi)
| Get the current status register of the given TWI peripheral.
uint32_t | TWI_GetMaskedStatus (Twi *pTwi)
| Returns the current status register of the given TWI peripheral, but masking interrupt sources which are not currently enabled.
void | TWI_SendSTOPCondition (Twi *pTwi)
| Sends a STOP condition. STOP Condition is sent just after completing the current byte transmission in master read mode.

## Detailed Description

Interface for configuration the Two Wire Interface (TWI) peripheral.

Definition in file twi.h.

## Function Documentation

uint8_t TWI_ByteReceived | ( | Twi * | pTwi ) |

Check if a byte have been receiced from TWI.

Parameters:

  pTwi | Pointer to an Twi instance.

Returns:
  1 if a byte has been received and can be read on the given TWI peripheral; otherwise, returns 0. This function resets the status register.

Definition at line 284 of file twi.c.

uint8_t TWI_ByteSent | ( | Twi * | pTwi ) |

Check if a byte have been sent to TWI.

Parameters:

  pTwi | Pointer to an Twi instance.

Returns:
  1 if a byte has been sent so another one can be stored for transmission; otherwise returns 0. This function clears the status register.

Definition at line 295 of file twi.c.

void TWI_ConfigureMaster | ( | Twi * | pTwi,
|  | uint32_t | dwTwCk,
|  | uint32_t | dwMCk
| ) |  |

Configures a TWI peripheral to operate in master mode, at the given frequency (in Hz). The duty cycle of the TWI clock is set to 50%.

Parameters:

  pTwi | Pointer to an Twi instance.
  twck | Desired TWI clock frequency.
  mck | Master clock frequency.

Definition at line 97 of file twi.c.

void TWI_ConfigureSlave | ( | Twi * | pTwi,
|  | uint8_t | slaveAddress
| ) |  |

Configures a TWI peripheral to operate in slave mode.

Parameters:

  pTwi | Pointer to an Twi instance.
  slaveAddress | Slave address.

Definition at line 146 of file twi.c.

void TWI_DisableIt | ( | Twi * | pTwi,
|  | uint32_t | sources
| ) |  |

Disables the selected interrupts sources on a TWI peripheral.

Parameters:

  pTwi | Pointer to an Twi instance.
  sources | Bitwise OR of selected interrupt sources.

Definition at line 329 of file twi.c.

void TWI_EnableIt | ( | Twi * | pTwi,
|  | uint32_t | sources
| ) |  |

Enables the selected interrupts sources on a TWI peripheral.

Parameters:

  pTwi | Pointer to an Twi instance.
  sources | Bitwise OR of selected interrupt sources.

Definition at line 316 of file twi.c.

uint32_t TWI_GetMaskedStatus | ( | Twi * | pTwi ) |

Returns the current status register of the given TWI peripheral, but masking interrupt sources which are not currently enabled.

Note:
  This resets the internal value of the status register, so further read may yield different values.

Parameters:

  pTwi | Pointer to an Twi instance.

Definition at line 358 of file twi.c.

uint32_t TWI_GetStatus | ( | Twi * | pTwi ) |

Get the current status register of the given TWI peripheral.

Note:
  This resets the internal value of the status register, so further read may yield different values.

Parameters:

  pTwi | Pointer to an Twi instance.

Returns:
  TWI status register.

Definition at line 344 of file twi.c.

uint8_t TWI_ReadByte | ( | Twi * | pTwi ) |

Reads a byte from the TWI bus. The read operation must have been started using TWI_StartRead() and a byte must be available (check with TWI_ByteReceived()).

Parameters:

  pTwi | Pointer to an Twi instance.

Returns:
  byte read.

Definition at line 221 of file twi.c.

void TWI_SendSTOPCondition | ( | Twi * | pTwi ) |

Sends a STOP condition. STOP Condition is sent just after completing the current byte transmission in master read mode.

Parameters:

  pTwi | Pointer to an Twi instance.

Definition at line 375 of file twi.c.

void TWI_StartRead | ( | Twi * | pTwi,
|  | uint8_t | address,
|  | uint32_t | iaddress,
|  | uint8_t | isize
| ) |  |

Starts a read operation on the TWI bus with the specified slave, it returns immediately. Data must then be read using TWI_ReadByte() whenever a byte is available (poll using TWI_ByteReceived()).

Parameters:

  pTwi | Pointer to an Twi instance.
  address | Slave address on the bus.
  iaddress | Optional internal address bytes.
  isize | Number of internal address bytes.

Definition at line 192 of file twi.c.

void TWI_StartWrite | ( | Twi * | pTwi,
|  | uint8_t | address,
|  | uint32_t | iaddress,
|  | uint8_t | isize,
|  | uint8_t | byte
| ) |  |

Starts a write operation on the TWI to access the selected slave, then returns immediately. A byte of data must be provided to start the write; other bytes are written next. after that to send the remaining bytes.

Parameters:

  pTwi | Pointer to an Twi instance.
  address | Address of slave to acccess on the bus.
  iaddress | Optional slave internal address.
  isize | Number of internal address bytes.
  byte | First byte to send.

Definition at line 254 of file twi.c.

Here is the call graph for this function:

void TWI_Stop | ( | Twi * | pTwi ) |

Sends a STOP condition on the TWI.

Parameters:

  pTwi | Pointer to an Twi instance.

Definition at line 176 of file twi.c.

uint8_t TWI_TransferComplete | ( | Twi * | pTwi ) |

Check if current transmission is complet.

Parameters:

  pTwi | Pointer to an Twi instance.

Returns:
  1 if the current transmission is complete (the STOP has been sent); otherwise returns 0.

Definition at line 306 of file twi.c.

void TWI_WriteByte | ( | Twi * | pTwi,
|  | uint8_t | byte
| ) |  |

Sends a byte of data to one of the TWI slaves on the bus.

Note:
  This function must be called once before TWI_StartWrite() with the first byte of data to send, then it shall be called repeatedly after that to send the remaining bytes.

Parameters:

  pTwi | Pointer to an Twi instance.
  byte | Byte to send.

Definition at line 236 of file twi.c.

All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines