Robobo
twi.h
Go to the documentation of this file.
1 /* ----------------------------------------------------------------------------
2  * SAM Software Package License
3  * ----------------------------------------------------------------------------
4  * Copyright (c) 2011-2012, Atmel Corporation
5  *
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following condition is met:
10  *
11  * - Redistributions of source code must retain the above copyright notice,
12  * this list of conditions and the disclaimer below.
13  *
14  * Atmel's name may not be used to endorse or promote products derived from
15  * this software without specific prior written permission.
16  *
17  * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
18  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
20  * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
21  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
23  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
24  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
25  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
26  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  * ----------------------------------------------------------------------------
28  */
29 
37 #ifndef _TWI_
38 #define _TWI_
39 
40 /*------------------------------------------------------------------------------
41  * Headers
42  *------------------------------------------------------------------------------*/
43 
44 #include "../chip.h"
45 
46 #include <stdint.h>
47 
48 /*----------------------------------------------------------------------------
49  * Macros
50  *----------------------------------------------------------------------------*/
51 /* Returns 1 if the TXRDY bit (ready to transmit data) is set in the given status register value.*/
52 #define TWI_STATUS_TXRDY(status) (((status) & TWI_SR_TXRDY) == TWI_SR_TXRDY)
53 
54 /* Returns 1 if the RXRDY bit (ready to receive data) is set in the given status register value.*/
55 #define TWI_STATUS_RXRDY(status) (((status) & TWI_SR_RXRDY) == TWI_SR_RXRDY)
56 
57 /* Returns 1 if the TXCOMP bit (transfer complete) is set in the given status register value.*/
58 #define TWI_STATUS_TXCOMP(status) (((status) & TWI_SR_TXCOMP) == TWI_SR_TXCOMP)
59 
60 #ifdef __cplusplus
61  extern "C" {
62 #endif
63 
64 /*----------------------------------------------------------------------------
65  * External function
66  *----------------------------------------------------------------------------*/
67 
68 extern void TWI_ConfigureMaster(Twi *pTwi, uint32_t twck, uint32_t mck);
69 
70 extern void TWI_SetClock( Twi *pTwi, uint32_t dwTwCk, uint32_t dwMCk );
71 
72 extern void TWI_ConfigureSlave(Twi *pTwi, uint8_t slaveAddress);
73 
74 extern void TWI_Disable(Twi *pTwi);
75 
76 extern void TWI_Stop(Twi *pTwi);
77 
78 extern void TWI_StartRead(
79  Twi *pTwi,
80  uint8_t address,
81  uint32_t iaddress,
82  uint8_t isize);
83 
84 extern uint8_t TWI_ReadByte(Twi *pTwi);
85 
86 extern void TWI_WriteByte(Twi *pTwi, uint8_t byte);
87 
88 extern void TWI_StartWrite(
89  Twi *pTwi,
90  uint8_t address,
91  uint32_t iaddress,
92  uint8_t isize,
93  uint8_t byte);
94 
95 extern uint8_t TWI_ByteReceived(Twi *pTwi);
96 
97 extern uint8_t TWI_ByteSent(Twi *pTwi);
98 
99 extern uint8_t TWI_TransferComplete(Twi *pTwi);
100 
101 extern void TWI_EnableIt(Twi *pTwi, uint32_t sources);
102 
103 extern void TWI_DisableIt(Twi *pTwi, uint32_t sources);
104 
105 extern uint32_t TWI_GetStatus(Twi *pTwi);
106 
107 extern uint32_t TWI_GetMaskedStatus(Twi *pTwi);
108 
109 extern void TWI_SendSTOPCondition(Twi *pTwi);
110 
111 #ifdef __cplusplus
112 }
113 #endif
114 
115 #endif /* #ifndef _TWI_ */
uint8_t TWI_TransferComplete(Twi *pTwi)
Check if current transmission is complet.
Definition: twi.c:323
void TWI_ConfigureSlave(Twi *pTwi, uint8_t slaveAddress)
Configures a TWI peripheral to operate in slave mode.
Definition: twi.c:150
uint32_t TWI_GetMaskedStatus(Twi *pTwi)
Returns the current status register of the given TWI peripheral, but masking interrupt sources which ...
Definition: twi.c:375
uint8_t TWI_ByteReceived(Twi *pTwi)
Check if a byte have been receiced from TWI.
Definition: twi.c:301
void TWI_SendSTOPCondition(Twi *pTwi)
Sends a STOP condition. STOP Condition is sent just after completing the current byte transmission in...
Definition: twi.c:392
void TWI_DisableIt(Twi *pTwi, uint32_t sources)
Disables the selected interrupts sources on a TWI peripheral.
Definition: twi.c:346
uint32_t TWI_GetStatus(Twi *pTwi)
Get the current status register of the given TWI peripheral.
Definition: twi.c:361
void TWI_EnableIt(Twi *pTwi, uint32_t sources)
Enables the selected interrupts sources on a TWI peripheral.
Definition: twi.c:333
void TWI_Disable(Twi *pTwi)
Disables the TWI.
Definition: twi.c:172
void TWI_Stop(Twi *pTwi)
Sends a STOP condition on the TWI.
Definition: twi.c:193
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 ...
Definition: twi.c:238
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)...
Definition: twi.c:97
void TWI_WriteByte(Twi *pTwi, uint8_t byte)
Sends a byte of data to one of the TWI slaves on the bus.
Definition: twi.c:253
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.
Definition: twi.c:271
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()).
Definition: twi.c:209
Twi hardware registers.
Definition: component_twi.h:41
uint8_t TWI_ByteSent(Twi *pTwi)
Check if a byte have been sent to TWI.
Definition: twi.c:312