mavishak / cnss-embedded

1 stars 0 forks source link

Debug session: i2c + clock #25

Open NaomiCreate opened 3 years ago

NaomiCreate commented 3 years ago

Project: STM32F103-I2C-PERIPH-TESTING

In the CLOCK.c file:

  1. We used an oscilloscope (a device that allows voltage measurement against time), and saw that a clock does not come out from pin A8 (PA8 is where we connected the MCLK).
  2. We changed the rate of pin A8 to 50 MHz from 2 MHz. GPIOA-> CRH | = 0x0000000B; // set PA8 (data sheet p.31) as Alternate function push-pull | frequency of 50 MHz
  3. As a result of the change we saw in the oscilloscope a sin wave, at a frequency of about 72MHz, and an amplitude of 275mV.
  4. In init_MCO, instead of the sysclk, we turned on the HSI, and we saw that the frequency varies to 8 MHz and an amplitude of 2.8V.
  5. We Run the code, stopped it, and saw that the lower four bits ofRCC-> CFGR have 0xA which means that PLL is enabled
  6. We put Break Point in the first row in the startup.s file and saw that it says that the bottom four bits in RCC-> CFGR are 0.
  7. We saw that in the startup.s file, the systemInit function changes the sysclk.

    Because the problem came from a file we attached to use libraries, we decided to continue to debug our project - without using libraries.

Project: stm32-f103rb-cnss

In the clock.c file:

  1. We replaced the void init_MCO (void) function with the revised version (after the change we made in section 2)
  2. An 8MHz clock comes out.

In the i2c.c file:

Note: We need to look at Chapter 7 in the reference manual (and not Chapter 8) because our microcontroller is Medium-density devices.

  1. We saw that in theI2C1_Read1Byte(uint8_t DeviceAddr, uint8_t addr) function there is a problem with generating start condition.

  2. Our instructor recommended using an external pull up (for PB7 and PB8). We used two 10k ohm resistors.

  3. We have not yet been able to generate start condition. So we checked that the pull up works (we checked that it allows changing the state of bits from 0 to 1): In function init_i2c1(void) We wrote:

    GPIOB-> CRL | = 0x55000000; // set as General purpose open drain, max speed 2 MHz.//For Debug
    GPIOB-> ODR | = 0x000000C0; // set // For Debug
    GPIOB-> ODR & = ~ (0x000000C0); // reset // For Debug

    And we saw that the pull up was fine.

    13. We decided to move forward with other issues in the project, and if we have time, we will return to the point where we stopped.

Our main was:

int main(void)
{
    set_sys_clock_to_32MHz();
    init_MCO();
    write_usart2((uint8_t*)("\r\n_______________\r\n"));//For test
    init_timer2();//for testing i2c
    init_i2c1();

    while(1)
    {
        /*Testing I2C with camera module*/
        if(I2C1_Read1Byte(0x43, 0x0A) == 0x76)
        {
            write_usart2((uint8_t*)("\r\nI2C Test Pass\r\n"));//For test
        }
        else
        {
            write_usart2((uint8_t*)("\r\nI2C Test Failed\r\n"));//For test
        }
        delay_with_timer2(500);//0.5 second
    }
}