iT邦幫忙

0

I2C設定問題

  • 分享至 

  • xImage

想請問一下!在程式裡面的I2C1->TIMINGR後面的值怎麼出來的

`__INLINE void Configure_I2C1_Slave(void)
{
/* Configure RCC for I2C1 /
/
(1) Enable the peripheral clock I2C1 /
/
(2) Use SysClk for I2C CLK /
RCC->APB1ENR |= RCC_APB1ENR_I2C1EN; /
(1) /
RCC->CFGR3 |= RCC_CFGR3_I2C1SW; /
(2) */

/* Configure I2C1, slave /
/
(3) Timing register value is computed with the AN4235 xls file,
fast Mode @400kHz with I2CCLK = 48MHz, rise time = 140ns,
fall time = 40ns /
/
(4) Periph enable, address match interrupt enable /
/
(5) 7-bit address = 0x5A /
/
(6) Enable own address 1 /
I2C1->TIMINGR = (uint32_t)0x00B00000; /
(3) /
I2C1->CR1 = I2C_CR1_PE | I2C_CR1_ADDRIE; /
(4) /
I2C1->OAR1 |= (uint32_t)(I2C1_OWN_ADDRESS << 1); /
(5) /
I2C1->OAR1 |= I2C_OAR1_OA1EN; /
(6) */

/* Configure IT /
/
(7) Set priority for I2C1_IRQn /
/
(8) Enable I2C1_IRQn /
NVIC_SetPriority(I2C1_IRQn, 0); /
(7) /
NVIC_EnableIRQ(I2C1_IRQn); /
(8) */
}`

圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 個回答

1
lens88
iT邦新手 5 級 ‧ 2021-03-09 10:37:06

/*
(3) Timing register value is computed with the AN4235 xls file,
fast Mode @400kHz with I2CCLK = 48MHz, rise time = 140ns,
fall time = 40ns /
*/
I2C1->TIMINGR = (uint32_t)0x00B00000; / (3) /

  1. 可以查一下MCU datasheet 有關I2C TIMINGR 這個register的設定方法
  2. 使用MCU原廠提供的tools (AN4235 xls file)
tom08211 iT邦新手 5 級 ‧ 2021-03-09 14:47:05 檢舉

不好意思!我也想要請問一下我想要找這個相關的語言的相關書籍有推薦的嗎?類似這樣的
I2C1->CR1 = I2C_CR1_PE | I2C_CR1_ADDRIE;
I2C1->OAR1 |= (uint32_t)(I2C1_OWN_ADDRESS << 1);

tom08211 iT邦新手 5 級 ‧ 2021-03-09 15:01:13 檢舉

我用的是STM32f072CB (ARM Cortex-M0)

我要發表回答

立即登入回答