2014-01-14 4 views
2

STM32F0 검색에 문제가 있습니다. 동일한 보드의 I2C2 (슬레이브)에 시작 조건과 주소를 보내려면 마스터와 같은 I2C1을 사용하고 있습니다. 신호를 유용하게 생성 할 수 있지만 IC2 (슬레이브)가 9 번째 클럭에서 ACK를 생성 할 수 없습니다.STM32 슬레이브 I2C 포트를 설정하는 방법

무엇이 잘못 되었습니까? 설정에 대한 다음 내 코드 :

void set_I2C(void){ 
    GPIO_InitTypeDef GPIO_InitStructure; 
    I2C_InitTypeDef I2C_InitStructure; 

    RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE); 
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1, ENABLE); 
    /* Configure the I2C clock source. The clock is derived from the HSI */ 
    RCC_I2CCLKConfig(RCC_I2C1CLK_SYSCLK); 


    GPIO_PinAFConfig(GPIOB, GPIO_PinSource6, GPIO_AF_1); 
    GPIO_PinAFConfig(GPIOB, GPIO_PinSource7, GPIO_AF_1); 


    //Configure pins: SCL and SDA ------------------ 
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7; 
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; 
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; 
    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; 
    GPIO_InitStructure.GPIO_OType = GPIO_OType_OD; 
    GPIO_Init(GPIOB, &GPIO_InitStructure); 



    I2C_DeInit(I2C1); 
    I2C_Cmd(I2C1, DISABLE); 
    I2C_InitStructure.I2C_AnalogFilter = I2C_AnalogFilter_Enable; 
    I2C_InitStructure.I2C_DigitalFilter = 0x00; 
    I2C_InitStructure.I2C_OwnAddress1 = 0x40; 
    I2C_InitStructure.I2C_Mode = I2C_Mode_I2C; 
    I2C_InitStructure.I2C_Ack = I2C_Ack_Enable; 
    I2C_InitStructure.I2C_Timing =0xB0420F13; //100KHz   

      I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit; 

    I2C_Init(I2C1, &I2C_InitStructure); 
    I2C_Cmd(I2C1, ENABLE); 


    //Set up of I2C2 
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C2, ENABLE); 
    RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE); 


    GPIO_PinAFConfig(GPIOB, GPIO_PinSource11, GPIO_AF_1); 
    GPIO_PinAFConfig(GPIOB, GPIO_PinSource10, GPIO_AF_1); 

    //Configure pins: SCL and SDA ------------------ 
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11 | GPIO_Pin_10; 
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; 
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; 
    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; 
    GPIO_InitStructure.GPIO_OType = GPIO_OType_OD; 
    GPIO_Init(GPIOB, &GPIO_InitStructure); 

    I2C_DeInit(I2C2); 
    I2C_Cmd(I2C2, DISABLE); 
    I2C_InitStructure.I2C_AnalogFilter = I2C_AnalogFilter_Disable; 
    I2C_InitStructure.I2C_DigitalFilter = 0x00; 
    I2C_InitStructure.I2C_OwnAddress1 = 0x30; 

    I2C_InitStructure.I2C_Mode = I2C_Mode_I2C; 
    I2C_InitStructure.I2C_Ack = I2C_Ack_Enable; 

    I2C_InitStructure.I2C_Timing =0xB0420F13; 
    I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit; 

    I2C_Init(I2C2, &I2C_InitStructure); 
    I2C_Cmd(I2C2, ENABLE); 



     I2C_ITConfig(I2C2, I2C_AcknowledgedAddress_7bit, ENABLE); 

    NVIC_InitTypeDef NVIC_InitStructure; 
/* Configure the I2C2 interrupt priority */ 
NVIC_InitStructure.NVIC_IRQChannel = I2C2_IRQn; 
NVIC_InitStructure.NVIC_IRQChannelPriority=1; 
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; 
NVIC_Init(&NVIC_InitStructure); 

}

+0

그래서, 누군가가 나를 도울 수 있습니까? 9th clk에서 ack을 생성 할 수 없습니다. – difedepe

답변