Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Unhiding twi functionality#79

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
apozharski wants to merge1 commit intoarduino:master
base:master
Choose a base branch
Loading
fromapozharski:master
Open
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletionslibraries/Wire/src/utility/twi.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -175,35 +175,35 @@ uint8_t TWI_MasterReady(void)
* Sets the baud rate used by TWI Master.
*
* \param frequency The required baud.
*
* \retval 0 If baud set correctly
* \retval 1 If baud not set due to being too high. > 1MHz
*/
void TWI_MasterSetBaud(uint32_t frequency){
uint8_t TWI_MasterSetBaud(uint32_t frequency){

//Formula is: BAUD = ((F_CLKPER/frequency) - F_CLKPER*T_RISE - 10)/2;
//Where T_RISE varies depending on operating frequency...
//From 1617 DS: 1000ns @ 100kHz / 300ns @ 400kHz / 120ns @ 1MHz

uint16_t t_rise;

if(frequency < 200000){
frequency = 100000;
if(frequency <= 100000){
t_rise = 1000;

} else if (frequency < 800000){
frequency = 400000;
} else if (frequency <= 400000){
t_rise = 300;

} else if (frequency < 1200000){
frequency = 1000000;
} else if (frequency <= 1000000){
t_rise = 120;

} else {
frequency = 100000;
t_rise = 1000;
return 1;
}

uint32_t baud = ((F_CPU_CORRECTED/frequency) - (((F_CPU_CORRECTED*t_rise)/1000)/1000)/1000 - 10)/2;
TWI0.MBAUD = (uint8_t)baud;

return 0;
}

/*! \brief TWI write transaction.
Expand DownExpand Up@@ -781,4 +781,4 @@ ISR(TWI0_TWIM_vect){

ISR(TWI0_TWIS_vect){
TWI_SlaveInterruptHandler();
}
}
2 changes: 1 addition & 1 deletionlibraries/Wire/src/utility/twi.h
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -75,7 +75,7 @@ void TWI_Flush(void);
void TWI_Disable(void);
TWI_BUSSTATE_t TWI_MasterState(void);
uint8_t TWI_MasterReady(void);
void TWI_MasterSetBaud(uint32_t frequency);
uint8_t TWI_MasterSetBaud(uint32_t frequency);
uint8_t TWI_MasterWrite(uint8_t slave_address,
uint8_t *write_data,
uint8_t bytes_to_write,
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp