mirror of
https://github.com/Sovichea/avr-i2c-library.git
synced 2025-10-16 16:04:47 +03:00
Updated Readme with example
This commit is contained in:
39
twi/twi_master.h
Normal file
39
twi/twi_master.h
Normal file
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* twi_master.h
|
||||
*
|
||||
* Created: 09-Jun-19 11:20:04 AM
|
||||
* Author: TEP SOVICHEA
|
||||
*/
|
||||
|
||||
|
||||
#ifndef TWI_MASTER_H_
|
||||
#define TWI_MASTER_H_
|
||||
|
||||
#include <avr/io.h>
|
||||
#include <util/twi.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#define DEBUG_LOG 0
|
||||
#define SUCCESS 0
|
||||
|
||||
#define TW_SCL_PIN PORTC5
|
||||
#define TW_SDA_PIN PORTC4
|
||||
|
||||
#define TW_SLA_W(ADDR) ((ADDR << 1) | TW_WRITE)
|
||||
#define TW_SLA_R(ADDR) ((ADDR << 1) | TW_READ)
|
||||
#define TW_READ_ACK 1
|
||||
#define TW_READ_NACK 0
|
||||
|
||||
typedef uint16_t ret_code_t;
|
||||
|
||||
typedef enum {
|
||||
TW_FREQ_100K,
|
||||
TW_FREQ_250K,
|
||||
TW_FREQ_400K
|
||||
} twi_freq_mode_t;
|
||||
|
||||
void tw_init(twi_freq_mode_t twi_freq, bool pullup_en);
|
||||
ret_code_t tw_master_transmit(uint8_t slave_addr, uint8_t* p_data, uint8_t len, bool repeat_start);
|
||||
ret_code_t tw_master_receive(uint8_t slave_addr, uint8_t* p_data, uint8_t len);
|
||||
|
||||
#endif /* TWI_MASTER_H_ */
|
Reference in New Issue
Block a user