Plant Monitor SAM3X8E
Loading...
Searching...
No Matches
twi.h
Go to the documentation of this file.
1
9
10#ifndef TWI_H
11#define TWI_H
12
13#include <stddef.h>
14#include "sam3xa.h"
15
29
36typedef struct
37{
38 uint32_t dadr; /* Target device address */
39 uint32_t iadr; /* Internal address (address within target device) */
40 twi_iadr_size_t iadr_size; /* Internal address size */
41} twi_cfg_t;
42
43/*================================
44 * TWI Pin Masks
45 *
46 * As per Arduino DUE specifications
47 *================================*/
48
49#define TWI0_SCL (1u << 18)
50#define TWI0_SDA (1u << 17)
51
52#define TWI0_PINS (TWI0_SCL | TWI0_SDA)
53
54/* Clock configuration */
55#define TWI_CKDIV 1
56#define TWI_CHDIV 208
57#define TWI_CLDIV 208
58
59/*================================
60 * Function Declarations
61 *================================*/
62
68void twi_init();
69
78void twi_configure(const twi_cfg_t* cfg);
79
86void twi_read(uint8_t* buffer, size_t len);
87
94void twi_write(const uint8_t* buffer, size_t len);
95
96#endif
TWI configuration parameters.
Definition twi.h:37
twi_iadr_size_t iadr_size
Definition twi.h:40
uint32_t iadr
Definition twi.h:39
uint32_t dadr
Definition twi.h:38
twi_iadr_size_t
TWI internal address size.
Definition twi.h:23
@ TWI_ADDR_1BYTE
Definition twi.h:25
@ TWI_ADDR_0BYTE
Definition twi.h:24
@ TWI_ADDR_2BYTE
Definition twi.h:26
@ TWI_ADDR_3BYTE
Definition twi.h:27
void twi_configure(const twi_cfg_t *cfg)
Configures TWI0 peripheral of SAM3X8E.
Definition twi.c:13
void twi_write(const uint8_t *buffer, size_t len)
Writes to TWI target device.
Definition twi.c:82
void twi_init()
Initializes TWI0 peripheral of SAM3X8E.
Definition twi.c:44
void twi_read(uint8_t *buffer, size_t len)
Reads from TWI target device.
Definition twi.c:62