LibDriver MCP4725
Loading...
Searching...
No Matches
driver_mcp4725_basic.c
Go to the documentation of this file.
1
37
39
40static mcp4725_handle_t gs_handle;
41
51{
52 uint8_t res;
53
54 /* link interface function */
62
63 /* set iic addr pin */
64 res = mcp4725_set_addr_pin(&gs_handle, addr_pin);
65 if (res != 0)
66 {
67 mcp4725_interface_debug_print("mcp4725: set addr pin failed.\n");
68
69 return 1;
70 }
71
72 /* mcp4725 init */
73 res = mcp4725_init(&gs_handle);
74 if (res != 0)
75 {
76 mcp4725_interface_debug_print("mcp4725: init failed.\n");
77
78 return 1;
79 }
80
81 /* set power mode */
83 if (res != 0)
84 {
85 mcp4725_interface_debug_print("mcp4725: set power mode failed.\n");
86 (void)mcp4725_deinit(&gs_handle);
87
88 return 1;
89 }
90
91 /* set mode */
93 if (res != 0)
94 {
95 mcp4725_interface_debug_print("mcp4725: set mode failed.\n");
96 (void)mcp4725_deinit(&gs_handle);
97
98 return 1;
99 }
100
101 /* set reference voltage */
103 if (res != 0)
104 {
105 mcp4725_interface_debug_print("mcp4725: set reference voltage failed.\n");
106 (void)mcp4725_deinit(&gs_handle);
107
108 return 1;
109 }
110
111 return 0;
112}
113
122uint8_t mcp4725_basic_write(float voltage_v)
123{
124 uint16_t value;
125 uint8_t res;
126
127 /* convert voltage to register */
128 res = mcp4725_convert_to_register(&gs_handle, voltage_v, (uint16_t *)&value);
129 if (res != 0)
130 {
131 return 1;
132 }
133
134 /* write voltage */
135 if (mcp4725_write(&gs_handle, (uint16_t)value) != 0)
136 {
137 return 1;
138 }
139 else
140 {
141 return 0;
142 }
143}
144
153{
154 /* close mcp4725 */
155 if (mcp4725_deinit(&gs_handle) != 0)
156 {
157 return 1;
158 }
159 else
160 {
161 return 0;
162 }
163}
driver mcp4725 basic header file
#define MCP4725_BASIC_DEFAULT_POWER_DOWN_MODE
mcp4725 basic example default definition
#define MCP4725_BASIC_DEFAULT_MODE
#define MCP4725_BASIC_DEFAULT_REFERENCE_VOLTAGE
struct mcp4725_handle_s mcp4725_handle_t
mcp4725 handle structure definition
uint8_t mcp4725_deinit(mcp4725_handle_t *handle)
close the chip
uint8_t mcp4725_set_power_mode(mcp4725_handle_t *handle, mcp4725_power_down_mode_t mode)
set the chip power mode
mcp4725_address_t
mcp4725 address enumeration definition
uint8_t mcp4725_write(mcp4725_handle_t *handle, uint16_t value)
write the dac value
uint8_t mcp4725_convert_to_register(mcp4725_handle_t *handle, float s, uint16_t *reg)
convert the dac value to the register data
uint8_t mcp4725_init(mcp4725_handle_t *handle)
initialize the chip
uint8_t mcp4725_set_reference_voltage(mcp4725_handle_t *handle, float ref_voltage)
set the chip reference voltage
uint8_t mcp4725_set_mode(mcp4725_handle_t *handle, mcp4725_mode_t mode)
set the chip mode
uint8_t mcp4725_set_addr_pin(mcp4725_handle_t *handle, mcp4725_address_t addr_pin)
set the chip address pin
uint8_t mcp4725_basic_write(float voltage_v)
basic example write
uint8_t mcp4725_basic_deinit(void)
basic example deinit
uint8_t mcp4725_basic_init(mcp4725_address_t addr_pin)
basic example init
uint8_t mcp4725_interface_iic_read_cmd(uint8_t addr, uint8_t *buf, uint16_t len)
interface iic bus read command
void mcp4725_interface_delay_ms(uint32_t ms)
interface delay ms
uint8_t mcp4725_interface_iic_write_cmd(uint8_t addr, uint8_t *buf, uint16_t len)
interface iic bus write command
void mcp4725_interface_debug_print(const char *const fmt,...)
interface print format data
uint8_t mcp4725_interface_iic_init(void)
interface iic bus init
uint8_t mcp4725_interface_iic_deinit(void)
interface iic bus deinit