AnsweredAssumed Answered

regarding i2c(bq27500/1) with stm32f407vg

Question asked by srinivasan.pavithra on Jun 23, 2014
regarding i2c
i am working on interface of stm32f407vg (i2c) with fuel gauge, while the program in completed i got zero errors.After loading and running the program i get only read output or write output what is the possible ways to get required output and why the output is not coming???????????
help me soon............. here's my program which i worked



001./* Includes ------------------------------------------------------------------*/
002.#include "main.h"
003.#include "usbd_hid_core.h"
004.#include "usbd_usr.h"
005.#include "usbd_desc.h"
006.#include "stm32f4xx_i2c.h"
007.#include "stdio.h"
008.#include "usbd_desc.h"
009.#include "stm32f4xx_usart.h"
010. 
011.#ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED
012.#if defined ( __ICCARM__ ) /*!< IAR Compiler */
013.    #pragma data_alignment = 4  
014.  #endif
015.#endif /* USB_OTG_HS_INTERNAL_DMA_ENABLED */
016.__ALIGN_BEGIN USB_OTG_CORE_HANDLE  USB_OTG_dev __ALIGN_END;
017.#ifdef __GNUC__
018.  /* With GCC/RAISONANCE, small printf (option LD Linker->Libraries->Small printf
019.     set to 'Yes') calls __io_putchar() */
020.  #define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
021.#else
022.  #define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
023.#endif /* __GNUC__ */
024. 
025.#define CR1_CLEAR_MASK            ((uint16_t)(USART_CR1_M | USART_CR1_PCE | \
026.                                              USART_CR1_PS | USART_CR1_TE | \
027.                                              USART_CR1_RE))   
028.   
029.#define CR3_CLEAR_MASK            ((uint16_t)(USART_CR3_RTSE | USART_CR3_CTSE))
030.     
031.#define TIMEOUT_MAX  10000
032.#define  I2C_CR1_START                       ((uint16_t)0x0100)            /*!<Start Generation */
033.#define I2C_ADDRESS        0x30F
034. 
035.void USART_SendData (   USART_TypeDef *     USARTx,
036.uint16_t    Data
037.)   ;
038. 
039.void I2C2_Config(void);
040. 
041.void RCC_Configuration(void)
042.{
043.  /* --------------------------- System Clocks Configuration -----------------*/
044.     
045.    /* GPIOC clock enable */
046.    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE);
047.  /* USART4 clock enable */
048.    RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART4, ENABLE);
049.     
050.}
051. 
052. 
053.void NVIC_Config(void)
054.{
055.  NVIC_InitTypeDef NVIC_InitStructure;
056. 
057.  /* Enable the USARTx Interrupt */
058.  NVIC_InitStructure.NVIC_IRQChannel = UART4_IRQn;
059.  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
060.  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
061.  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
062.  NVIC_Init(&NVIC_InitStructure);
063.}
064.void GPIO_Configuration(void)
065.{
066.  GPIO_InitTypeDef GPIO_InitStructure;
067.     
068.    GPIO_PinAFConfig(GPIOC, GPIO_PinSource10, GPIO_AF_UART4);/* UART4_TX */
069.  GPIO_PinAFConfig(GPIOC, GPIO_PinSource11, GPIO_AF_UART4);/* UART4_RX */
070.    GPIO_PinAFConfig(GPIOC, GPIO_PinSource12, GPIO_AF_UART5);/* UART5_TX */
071.  GPIO_PinAFConfig(GPIOD, GPIO_PinSource2, GPIO_AF_UART5);/* UART5_RX */
072. 
073.  /*-------------------------- GPIO Configuration ----------------------------*/
074.  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10 | GPIO_Pin_11;
075.  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
076.  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
077.  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
078.  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
079.  GPIO_Init(GPIOC, &GPIO_InitStructure);
080. 
081.         
082. 
083.    }
084.void USART4_Configuration(void)
085.{
086.    USART_InitTypeDef USART_InitStructure;
087.//  USART_ClockInitTypeDef USART_ClockInitStruct;
088.  /* USARTx configuration ------------------------------------------------------*/
089.  /* USARTx configured as follow:
090.        - BaudRate = 9600 baud
091.        - Word Length = 8 Bits
092.        - Two Stop Bit
093.        - Odd parity
094.        - Hardware flow control disabled (RTS and CTS signals)
095.        - Receive and transmit enabled
096.  */
097.    USART_InitStructure.USART_BaudRate = 115200;  //115200;
098.  USART_InitStructure.USART_WordLength = USART_WordLength_8b;
099.  USART_InitStructure.USART_StopBits = USART_StopBits_1;
100.  USART_InitStructure.USART_Parity = USART_Parity_No;
101.  USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
102.  USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
103. 
104.    USART_Init(UART4,&USART_InitStructure);  //uart
105. 
106.    USART_Cmd(UART4, ENABLE);
107.}
108. 
109./**
110.  * @brief  Initializes the USARTx peripheral according to the specified
111.  *         parameters in the USART_InitStruct .
112.  * @param  USARTx: where x can be 1, 2, 3, 4, 5 or 6 to select the USART or
113.  *         UART peripheral.
114.  * @param  USART_InitStruct: pointer to a USART_InitTypeDef structure that contains
115.  *         the configuration information for the specified USART peripheral.
116.  * @retval None
117.  */
118.void USART_Init(USART_TypeDef* USARTx, USART_InitTypeDef* USART_InitStruct)
119.{
120.  uint32_t tmpreg = 0x00, apbclock = 0x00;
121.  uint32_t integerdivider = 0x00;
122.  uint32_t fractionaldivider = 0x00;
123.  RCC_ClocksTypeDef RCC_ClocksStatus;
124. 
125.  /* Check the parameters */
126.  assert_param(IS_USART_ALL_PERIPH(USARTx));
127.  assert_param(IS_USART_BAUDRATE(USART_InitStruct->USART_BaudRate)); 
128.  assert_param(IS_USART_WORD_LENGTH(USART_InitStruct->USART_WordLength));
129.  assert_param(IS_USART_STOPBITS(USART_InitStruct->USART_StopBits));
130.  assert_param(IS_USART_PARITY(USART_InitStruct->USART_Parity));
131.  assert_param(IS_USART_MODE(USART_InitStruct->USART_Mode));
132.  assert_param(IS_USART_HARDWARE_FLOW_CONTROL(USART_InitStruct->USART_HardwareFlowControl));
133. 
134.  /* The hardware flow control is available only for USART1, USART2, USART3 and USART6 */
135.  if (USART_InitStruct->USART_HardwareFlowControl != USART_HardwareFlowControl_None)
136.  {
137.    assert_param(IS_USART_1236_PERIPH(USARTx));
138.  }
139. 
140./*---------------------------- USART CR2 Configuration -----------------------*/
141.  tmpreg = USARTx->CR2;
142. 
143.  /* Clear STOP[13:12] bits */
144.  tmpreg &= (uint32_t)~((uint32_t)USART_CR2_STOP);
145. 
146.  /* Configure the USART Stop Bits, Clock, CPOL, CPHA and LastBit :
147.      Set STOP[13:12] bits according to USART_StopBits value */
148.  tmpreg |= (uint32_t)USART_InitStruct->USART_StopBits;
149.   
150.  /* Write to USART CR2 */
151.  USARTx->CR2 = (uint16_t)tmpreg;
152. 
153./*---------------------------- USART CR1 Configuration -----------------------*/
154.  tmpreg = USARTx->CR1;
155. 
156.  /* Clear M, PCE, PS, TE and RE bits */
157.  tmpreg &= (uint32_t)~((uint32_t)CR1_CLEAR_MASK);
158. 
159.  /* Configure the USART Word Length, Parity and mode:
160.     Set the M bits according to USART_WordLength value
161.     Set PCE and PS bits according to USART_Parity value
162.     Set TE and RE bits according to USART_Mode value */
163.  tmpreg |= (uint32_t)USART_InitStruct->USART_WordLength | USART_InitStruct->USART_Parity |
164.            USART_InitStruct->USART_Mode;
165. 
166.  /* Write to USART CR1 */
167.  USARTx->CR1 = (uint16_t)tmpreg;
168. 
169./*---------------------------- USART CR3 Configuration -----------------------*/ 
170.  tmpreg = USARTx->CR3;
171. 
172.  /* Clear CTSE and RTSE bits */
173.  tmpreg &= (uint32_t)~((uint32_t)CR3_CLEAR_MASK);
174. 
175.  /* Configure the USART HFC :
176.      Set CTSE and RTSE bits according to USART_HardwareFlowControl value */
177.  tmpreg |= USART_InitStruct->USART_HardwareFlowControl;
178. 
179.  /* Write to USART CR3 */
180.  USARTx->CR3 = (uint16_t)tmpreg;
181. 
182./*---------------------------- USART BRR Configuration -----------------------*/
183.  /* Configure the USART Baud Rate */
184.  RCC_GetClocksFreq(&RCC_ClocksStatus);
185. 
186.  if ((USARTx == USART1) || (USARTx == USART6))
187.  {
188.    apbclock = RCC_ClocksStatus.PCLK2_Frequency;
189.  }
190.  else
191.  {
192.    apbclock = RCC_ClocksStatus.PCLK1_Frequency;
193.  }
194.   
195.  /* Determine the integer part */
196.  if ((USARTx->CR1 & USART_CR1_OVER8) != 0)
197.  {
198.    /* Integer part computing in case Oversampling mode is 8 Samples */
199.    integerdivider = ((25 * apbclock) / (2 * (USART_InitStruct->USART_BaudRate)));   
200.  }
201.  else /* if ((USARTx->CR1 & USART_CR1_OVER8) == 0) */
202.  {
203.    /* Integer part computing in case Oversampling mode is 16 Samples */
204.    integerdivider = ((25 * apbclock) / (4 * (USART_InitStruct->USART_BaudRate)));   
205.  }
206.  tmpreg = (integerdivider / 100) << 4;
207. 
208.  /* Determine the fractional part */
209.  fractionaldivider = integerdivider - (100 * (tmpreg >> 4));
210. 
211.  /* Implement the fractional part in the register */
212.  if ((USARTx->CR1 & USART_CR1_OVER8) != 0)
213.  {
214.    tmpreg |= ((((fractionaldivider * 8) + 50) / 100)) & ((uint8_t)0x07);
215.  }
216.  else /* if ((USARTx->CR1 & USART_CR1_OVER8) == 0) */
217.  {
218.    tmpreg |= ((((fractionaldivider * 16) + 50) / 100)) & ((uint8_t)0x0F);
219.  }
220.   
221.  /* Write to USART BRR register */
222.  USARTx->BRR = (uint16_t)tmpreg;
223.}
224.void USART_Cmd(USART_TypeDef* USARTx, FunctionalState NewState)
225.{
226.  /* Check the parameters */
227.  assert_param(IS_USART_ALL_PERIPH(USARTx));
228.  assert_param(IS_FUNCTIONAL_STATE(NewState));
229.   
230.  if (NewState != DISABLE)
231.  {
232.    /* Enable the selected USART by setting the UE bit in the CR1 register */
233.    USARTx->CR1 |= USART_CR1_UE;
234.  }
235.  else
236.  {
237.    /* Disable the selected USART by clearing the UE bit in the CR1 register */
238.    USARTx->CR1 &= (uint16_t)~((uint16_t)USART_CR1_UE);
239.  }
240.}
241. 
242.FlagStatus USART_GetFlagStatus(USART_TypeDef* USARTx, uint16_t USART_FLAG)
243.{
244.  FlagStatus bitstatus = RESET;
245.  /* Check the parameters */
246.  assert_param(IS_USART_ALL_PERIPH(USARTx));
247.  assert_param(IS_USART_FLAG(USART_FLAG));
248. 
249.  /* The CTS flag is not available for UART4 and UART5 */
250.  if (USART_FLAG == USART_FLAG_CTS)
251.  {
252.    assert_param(IS_USART_1236_PERIPH(USARTx));
253.  }
254.     
255.  if ((USARTx->SR & USART_FLAG) != (uint16_t)RESET)
256.  {
257.    bitstatus = SET;
258.  }
259.  else
260.  {
261.    bitstatus = RESET;
262.  }
263.  return bitstatus;
264.}
265.void USART_SendData(USART_TypeDef* USARTx, uint16_t Data)
266.{
267.  /* Check the parameters */
268.  assert_param(IS_USART_ALL_PERIPH(USARTx));
269.  assert_param(IS_USART_DATA(Data));
270.     
271.  /* Transmit Data */
272.  USARTx->DR = (Data & (uint16_t)0x01FF);
273.}
274./*int fputc(int ch, FILE * f)
275.{
276.  // Transmit the character using USART1
277.  //USART_SendData(USART1, (u8) ch);
278. 
279. // Wait until transmit finishes
280.  //while (USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET);
281. 
282.  return ch;
283.}   */  
284. 
285./* Buffer used for transmission */
286.//uint8_t aTxBuffer[] = " hello world ";
287. 
288./* Buffer used for reception */
289.//uint16_t aRxBuffer[RXBUFFERSIZE];
290. /* Private variables ---------------------------------------------------------*/
291./* I2C handler declaration */
292./* Private function prototypes -----------------------------------------------*/
293.uint8_t fuelgaugeConfig();
294.static uint32_t Demo_USBConfig(void);
295.static void TIM4_Config(void);
296.//static void Demo_Exec(void);
297.uint8_t SingleRandomWrite(uint8_t Device, uint16_t Addr, uint8_t Data);
298.uint8_t SingleRandomRead(uint8_t Device, uint16_t Addr);
299./* Private functions ---------------------------------------------------------*/
300. 
301./**
302.  * @brief  Main program.
303.  * @param  None
304.  * @retval None
305.  */
306.int main(void)
307.{
308.    uint8_t dd, ii;
309.    int m,n;
310.    I2C2_Config();
311.    NVIC_Config();                                  //***
312.    RCC_Configuration();                            //***
313.    GPIO_Configuration();                            //****
314.    USART4_Configuration();                            //***
315.     //printf("Hello World!\r\n"); 
316.     
317.     
318.    for(m=0;m<65000;m++)
319.    {
320.         for(n=0;n<650;n++)
321.             {}
322.         }
323.     
324.        ii=SingleRandomWrite(0xAA, 0x07, 0x04);
325.        printf("\n\r wrote 0x%x " ,ii);
326.             
327.        dd = SingleRandomRead(0xAB , 0x06);
328.        printf("\n\r read 0x%x " ,dd);
329.     
330.     
331.      while(1)
332.      {
333.         
334.      }
335.      
336.}
337./**
338.  * @brief  Writes a byte at a specific fuel register
339.  * @param  Device: fuelguage write address.
340.  * @param  Addr:  fuelguage register address.
341.  * @param  Data: data to be written to the specific register
342.  * @retval 0x00 if write operation is OK.
343.  *         0xFF if timeout condition occured (device not connected or bus error).
344.  */
345.uint8_t SingleRandomWrite(uint8_t Device, uint16_t Addr, uint8_t Data)
346.{
347.  uint32_t timeout = TIMEOUT_MAX;
348.   
349.  /* Generate the Start Condition */
350.  I2C_GenerateSTART(I2C2, ENABLE);
351. 
352.  /* Test on I2C2 EV5 and clear it */
353.  timeout = TIMEOUT_MAX; /* Initialize timeout value */
354.  while(!I2C_CheckEvent(I2C2, I2C_EVENT_MASTER_MODE_SELECT))
355.  {
356.    /* If the timeout delay is exeeded, exit with error code */
357.    if ((timeout--) == 0)
358.            {
359.                        return 0xff;
360.            }
361.  }
362.   printf("\n master mode selected in write");
363.  /* Send DCMI selected device slave Address for write */
364.  I2C_Send7bitAddress(I2C2, Device, I2C_Direction_Transmitter);
365.  
366.  /* Test on I2C2 EV6 and clear it */
367.  timeout = TIMEOUT_MAX; /* Initialize timeout value */
368.  while(!I2C_CheckEvent(I2C2, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED))
369.  {
370.    /* If the timeout delay is exeeded, exit with error code */
371.    if ((timeout--) == 0)
372.            {
373.                    return 0xFF;
374.          }
375.  }
376. printf("\n transmitter mode selected in write");
377.  /* Send I2C2 location address LSB */
378.  I2C_SendData(I2C2, (uint8_t)(Addr));
379.     
380. 
381.  /* Test on I2C2 EV8 and clear it */
382.  timeout = TIMEOUT_MAX; /* Initialize timeout value */
383.  while(!I2C_CheckEvent(I2C2, I2C_EVENT_MASTER_BYTE_TRANSMITTED))
384.  {
385.       
386.    /* If the timeout delay is exeeded, exit with error code */
387.    if ((timeout--) == 0)
388.        {
389.                        return 0xFF;
390.        }
391.  }
392.  printf("\n checkevent master byte transmitted in write");
393.  /* Send Data */
394.  I2C_SendData(I2C2, Data);   
395. 
396.  /* Test on I2C2 EV8 and clear it */
397.  timeout = TIMEOUT_MAX; /* Initialize timeout value */
398.  while(!I2C_CheckEvent(I2C2, I2C_EVENT_MASTER_BYTE_TRANSMITTED))
399.  {
400.         
401.    /* If the timeout delay is exeeded, exit with error code */
402.    if ((timeout--) == 0)
403.        {          
404.            return 0xFF;
405.        }
406.  } 
407. printf("\n i2c senddata master byte transmitted in write");
408.  /* Send I2C2 STOP Condition */
409.  I2C_GenerateSTOP(I2C2, ENABLE);
410.   
411.  /* If operation is OK, return 0 */
412.  return 0;
413.}
414. 
415. 
416. 
417.uint8_t SingleRandomRead(uint8_t Device, uint16_t Addr)
418.{
419.  uint32_t timeout = TIMEOUT_MAX;
420.  uint8_t Data = 0;
421. 
422.  /* Generate the Start Condition */
423.  I2C_GenerateSTART(I2C2, ENABLE);
424. 
425.  /* Test on I2C2 EV5 and clear it */
426.  timeout = TIMEOUT_MAX; /* Initialize timeout value */
427.  while(!I2C_CheckEvent(I2C2, I2C_EVENT_MASTER_MODE_SELECT))
428.  {
429.    /* If the timeout delay is exeeded, exit with error code */
430.    if ((timeout--) == 0)
431.            {
432.                return 0xff;
433.        }
434.  }
435.  printf("\n i2c enabled inread");
436.  /* Send DCMI selcted device slave Address for write */
437.  I2C_Send7bitAddress(I2C2, Device, I2C_Direction_Transmitter);                     
438.     
439.  
440.  /* Test on I2C2 and clear it */
441.  timeout = TIMEOUT_MAX; /* Initialize timeout value */
442.  while(!I2C_CheckEvent(I2C2, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED))
443.  {
444.    /* If the timeout delay is exeeded, exit with error code */
445.    if ((timeout--) == 0)
446.            {
447.            return 0xFF;
448.        }
449.  }
450.    printf("\n master transmitter mode slected in read");
451. 
452.  /* Send I2C2 location address LSB */
453.  I2C_SendData(I2C2, (uint8_t)(Addr));
454. 
455.  /* Test on I2C2 EV8 and clear it */
456.  timeout = TIMEOUT_MAX; /* Initialize timeout value */
457.  while(!I2C_CheckEvent(I2C2, I2C_EVENT_MASTER_BYTE_TRANSMITTED))
458.  {
459.    /* If the timeout delay is exeeded, exit with error code */
460.    if ((timeout--) == 0)
461.        {
462.            return 0xFF;
463.        }
464.  }
465.    printf("\n master byte transmitted in read");
466. 
467.  /* Clear AF flag if arised */
468.  I2C2->SR1 |= (uint16_t)0x0400;
469. 
470.  /* Generate the Start Condition */
471.  I2C_GenerateSTART(I2C2, ENABLE);
472.   
473.  /* Test on I2C2 EV6 and clear it */
474.  timeout = TIMEOUT_MAX; /* Initialize timeout value */
475.  while(!I2C_CheckEvent(I2C2, I2C_EVENT_MASTER_MODE_SELECT))
476.  {
477.    /* If the timeout delay is exeeded, exit with error code */
478.    if ((timeout--) == 0)
479.        {          
480.            return 0xFF;
481.        }
482.  }
483.        printf("\n checkevent master mode slected in read");
484.     
485.  /* Send DCMI selcted device slave Address for write */
486.  I2C_Send7bitAddress(I2C2, Device, I2C_Direction_Receiver);
487.    
488.  /* Test on I2C2 EV6 and clear it */
489.  timeout = TIMEOUT_MAX; /* Initialize timeout value */
490.  while(!I2C_CheckEvent(I2C2, I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED))
491.  {
492.    /* If the timeout delay is exeeded, exit with error code */
493.    if ((timeout--) == 0)
494.        {
495.        return 0xFF;
496.        }
497.  } 
498.                    printf("\n checkevent master receiver mode slected in read");
499.     
500.  /* Prepare an NACK for the next data received */
501.  I2C_AcknowledgeConfig(I2C2, DISABLE);
502. 
503.  /* Test on I2C2 EV7 and clear it */
504.  timeout = TIMEOUT_MAX; /* Initialize timeout value */
505.  while(!I2C_CheckEvent(I2C2, I2C_EVENT_MASTER_BYTE_RECEIVED))
506.  {
507.    /* If the timeout delay is exeeded, exit with error code */
508.    if ((timeout--) == 0)
509.        {          
510.            return 0xFF;
511.        }
512.  }  
513.        printf("\n checkevent master byte received in read");
514.         
515.  /* Prepare Stop after receiving data */
516.  I2C_GenerateSTOP(I2C2, ENABLE);
517. 
518.  /* Receive the Data */
519.  Data = I2C_ReceiveData(I2C2);
520. 
521.  /* return the read data */
522.  return Data;
523.}
524. 
525. 
526. 
527. 
528.PUTCHAR_PROTOTYPE
529.{
530.  /* Place your implementation of fputc here */
531.  /* e.g. write a character to the USART */
532.  USART_SendData(UART4, (uint8_t) ch);
533. 
534.  /* Loop until the end of transmission */
535.  while (USART_GetFlagStatus(UART4, USART_FLAG_TC) == RESET)
536.  {}
537. 
538.  return ch;
539.}
540. 
541.void I2C2_Config(void)
542.{
543.  GPIO_InitTypeDef GPIO_InitStructure;
544.  I2C_InitTypeDef  I2C_InitStruct;
545. 
546. /* I2C2 clock enable */
547.  RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C2, ENABLE);
548.  /* GPIOB clock enable */
549.  RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE);
550. 
551.     
552.    // Configure I2C SCL and SDA pins
553.  /* Connect I2C2 pins to AF4 ************************************************/
554.  GPIO_PinAFConfig(GPIOB, GPIO_PinSource10, GPIO_AF_I2C2); //SCL
555.  GPIO_PinAFConfig(GPIOB, GPIO_PinSource11, GPIO_AF_I2C2);  //SDA
556.   
557.  /* Configure I2C2 GPIOs *****************************************************/ 
558.  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10 | GPIO_Pin_11;
559.  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
560.  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_25MHz;
561.  GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
562.  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;  
563.  GPIO_Init(GPIOB, &GPIO_InitStructure);
564. 
565.  /* Configure I2C2 ***********************************************************/ 
566.  /* I2C DeInit */  
567.  I2C_DeInit(I2C2);
568.     
569.    //i2c.init(mode, *, addr=0xfe, baudrate=400000, gencall=False)
570.  /* Enable the I2C peripheral */
571.  I2C_Cmd(I2C2, ENABLE);
572.  
573.  /* Set the I2C structure parameters */
574.     
575.  I2C_InitStruct.I2C_Mode = I2C_Mode_I2C;
576.  I2C_InitStruct.I2C_DutyCycle = I2C_DutyCycle_2;
577.  I2C_InitStruct.I2C_OwnAddress1 = 0xFE;
578.  I2C_InitStruct.I2C_Ack = I2C_Ack_Enable;
579.  I2C_InitStruct.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
580.  I2C_InitStruct.I2C_ClockSpeed = 30000;
581.   
582.  /* Initialize the I2C peripheral w/ selected parameters */
583.  I2C_Init(I2C2, &I2C_InitStruct);
584.}
585. 
586.static uint32_t Demo_USBConfig(void)
587.{
588.  USBD_Init(&USB_OTG_dev,
589.            USB_OTG_FS_CORE_ID,
590.            &USR_desc,
591.            &USBD_HID_cb,
592.            &USR_cb);
593.   
594.  return 0;
595.}


Outcomes