File tree 2 files changed +11
-11
lines changed
libraries/Wire/src/utility
2 files changed +11
-11
lines changed Original file line number Diff line number Diff line change @@ -175,35 +175,35 @@ uint8_t TWI_MasterReady(void)
175
175
* Sets the baud rate used by TWI Master.
176
176
*
177
177
* \param frequency The required baud.
178
+ *
179
+ * \retval 0 If baud set correctly
180
+ * \retval 1 If baud not set due to being too high. > 1MHz
178
181
*/
179
- void TWI_MasterSetBaud (uint32_t frequency ){
182
+ uint8_t TWI_MasterSetBaud (uint32_t frequency ){
180
183
181
184
// Formula is: BAUD = ((F_CLKPER/frequency) - F_CLKPER*T_RISE - 10)/2;
182
185
// Where T_RISE varies depending on operating frequency...
183
186
// From 1617 DS: 1000ns @ 100kHz / 300ns @ 400kHz / 120ns @ 1MHz
184
187
185
188
uint16_t t_rise ;
186
189
187
- if (frequency < 200000 ){
188
- frequency = 100000 ;
190
+ if (frequency <= 100000 ){
189
191
t_rise = 1000 ;
190
192
191
- } else if (frequency < 800000 ){
192
- frequency = 400000 ;
193
+ } else if (frequency <= 400000 ){
193
194
t_rise = 300 ;
194
195
195
- } else if (frequency < 1200000 ){
196
- frequency = 1000000 ;
196
+ } else if (frequency <= 1000000 ){
197
197
t_rise = 120 ;
198
198
199
199
} else {
200
- frequency = 100000 ;
201
- t_rise = 1000 ;
200
+ return 1 ;
202
201
}
203
202
204
203
uint32_t baud = ((F_CPU_CORRECTED /frequency ) - (((F_CPU_CORRECTED * t_rise )/1000 )/1000 )/1000 - 10 )/2 ;
205
204
TWI0 .MBAUD = (uint8_t )baud ;
206
205
206
+ return 0 ;
207
207
}
208
208
209
209
/*! \brief TWI write transaction.
@@ -781,4 +781,4 @@ ISR(TWI0_TWIM_vect){
781
781
782
782
ISR (TWI0_TWIS_vect ){
783
783
TWI_SlaveInterruptHandler ();
784
- }
784
+ }
Original file line number Diff line number Diff line change @@ -75,7 +75,7 @@ void TWI_Flush(void);
75
75
void TWI_Disable (void );
76
76
TWI_BUSSTATE_t TWI_MasterState (void );
77
77
uint8_t TWI_MasterReady (void );
78
- void TWI_MasterSetBaud (uint32_t frequency );
78
+ uint8_t TWI_MasterSetBaud (uint32_t frequency );
79
79
uint8_t TWI_MasterWrite (uint8_t slave_address ,
80
80
uint8_t * write_data ,
81
81
uint8_t bytes_to_write ,
You can’t perform that action at this time.
0 commit comments