nicklasp
Newbie level 4
Hi!
I am new to this forum and seeking help. I am working on a PMBus compliance tester. PMBus extends SMBus which extends the I2C bus.
I think I have initialized the I2C peripheral on a STM32F103ZE correct. However, I cannot generate a start condition. I am using pull-up resistors and the signals is high all the time.
This is my code:
Now, I am stuck at the last while-loop since the start condition is never generated.
I have been working with this problem for long time now and would really need som guidance.
Here are some printscreens from the debugger:
I am new to this forum and seeking help. I am working on a PMBus compliance tester. PMBus extends SMBus which extends the I2C bus.
I think I have initialized the I2C peripheral on a STM32F103ZE correct. However, I cannot generate a start condition. I am using pull-up resistors and the signals is high all the time.
This is my code:
Code:
unsigned int dier;
unsigned short cnt;
unsigned short tmpreg = 0;
unsigned short freqrange = 0;
unsigned short result = 0;
/* Enable periphereal clocks */
RCC->APB2ENR |= RCC_APB2ENR_IOPBEN;
RCC->APB2ENR |= RCC_APB2ENR_AFIOEN;
RCC->APB1ENR |= RCC_APB1ENR_TIM2EN;
RCC->APB1ENR |= RCC_APB1ENR_I2C1EN;
/* Pin: Alternate function, open drain */
GPIOB->CRL |= (GPIO_CRL_CNF6_0 |
GPIO_CRL_CNF6_1 |
GPIO_CRL_CNF7_0 |
GPIO_CRL_CNF7_1 |
GPIO_CRL_CNF5_0 |
GPIO_CRL_CNF5_1 |
GPIO_CRL_MODE5_0 |
GPIO_CRL_MODE5_1 |
GPIO_CRL_MODE6_0 |
GPIO_CRL_MODE6_1 |
GPIO_CRL_MODE7_0 |
GPIO_CRL_MODE7_1 );
/* Enable I2C1 reset state */
RCC->APB1RSTR |= RCC_APB1RSTR_I2C1RST;
/* Release I2C1 from reset state */
RCC->APB1RSTR &= ~RCC_APB1RSTR_I2C1RST;
/*---------------------------- I2C1 CR2 Configuration ------------------------*/
/* Get the I2Cx CR2 value */
tmpreg = I2C1->CR2;
/* Clear frequency FREQ[5:0] bits */
tmpreg &= ((unsigned char)0xFFC0);
/* Get pclk1 frequency value */
RCC_GetClocksFreq(&rcc_clocks);
pclk1 = rcc_clocks.PCLK1_Frequency;
/* Set frequency bits depending on pclk1 value */
freqrange = (unsigned short)(pclk1 / 1000000);
/* Write to I2Cx CR2 */
I2C1->CR2 = ((freqrange) | I2C_CR2_ITEVTEN | I2C_CR2_ITERREN );
/*---------------------------- I2Cx CCR Configuration --------------------*/
/* Disable the selected I2C peripheral to configure TRISE */
I2C1->CR1 = 0;
/* Reset tmpreg value */
/* Clear F/S, DUTY and CCR[11:0] bits */
tmpreg = 0;
/* Configure speed in standard mode */
result = (unsigned short)(pclk1 / (I2C_CLOCKSPEED << 1));
/* Set speed value for standard mode */
tmpreg |= result;
/* Set Maximum Rise Time for standard mode */
I2C1->TRISE = freqrange + 1;
/* Write to I2C CCR */
I2C1->CCR = tmpreg;
/*---------------------------- I2Cx CR1 Configuration --------------------*/
/* Enable the selected I2C peripheral */
I2C1->CR1 = I2C_CR1_PE;// |
// I2C_CR1_SMBUS |
// I2C_CR1_SMBTYPE ;
// I2C_CR1_ENPEC |
// I2C_CR1_ACK );
/*---------------------------- I2Cx OAR Configuration --------------------*/
/* Set I2Cx Own Address1 and acknowledged address */
I2C1->OAR1 = ((SMB_ADR_HOST << 1) + (1 << 14));
/*---------------------------- Setup I2C IRQs ----------------------------*/
NVIC_SetPriority(I2C1_EV_IRQn, SMB_IRQ_PRIO);
NVIC_EnableIRQ(I2C1_EV_IRQn);
NVIC_SetPriority(I2C1_ER_IRQn, SMB_IRQ_PRIO);
NVIC_EnableIRQ(I2C1_ER_IRQn);
/* Generates the start condition */
I2C1->CR1 |= I2C_CR1_START;
/* Wait until the START condition is generated on the bus:
the START bit is cleared by hardware */
while ((I2C1->CR1&0x100) == 0x100);
Now, I am stuck at the last while-loop since the start condition is never generated.
I have been working with this problem for long time now and would really need som guidance.
Here are some printscreens from the debugger: