| BlueNRG-1 SDK drivers APIs

- Main Page
- Modules
- Classes
- Files

- File List
- File Members

SDK_EVAL_I2C.c
Go to the documentation of this file.
1
24 /* Includes ------------------------------------------------------------------*/
25 #include "SDK_EVAL_I2C.h"
26
27
53 #define I2C_TX_DR_BASE_ADDR (SDK_EVAL_I2C_BASE + 0x10)
54
55 #define I2C_RX_DR_BASE_ADDR (SDK_EVAL_I2C_BASE + 0x18)
56
57
79 uint8_t i2c_buffer_tx[I2C_BUFF_SIZE];
80 uint8_t i2c_buffer_rx[I2C_BUFF_SIZE];
81
85 volatile FlagStatus i2c_eot = SET;
86
87
126 ErrorStatus SdkEvalI2CInit(uint32_t baudrate)
127 {
128 GPIO_InitType GPIO_InitStructure;
129 I2C_InitType I2C_InitStruct;
130
131 /* Enable I2C and GPIO clocks */
132 if(SDK_EVAL_I2C == I2C2) {
133 SysCtrl_PeripheralClockCmd(CLOCK_PERIPH_GPIO | CLOCK_PERIPH_I2C2, ENABLE);
134 }
135 else {
136 SysCtrl_PeripheralClockCmd(CLOCK_PERIPH_GPIO | CLOCK_PERIPH_I2C1, ENABLE);
137 }
138
139 /* Configure I2C pins */
140 GPIO_InitStructure.GPIO_Pin = SDK_EVAL_I2C_CLK_PIN ;
141 GPIO_InitStructure.GPIO_Mode = SDK_EVAL_I2C_CLK_MODE;
142 GPIO_InitStructure.GPIO_Pull = DISABLE;
143 GPIO_InitStructure.GPIO_HighPwr = DISABLE;
144 GPIO_Init(&GPIO_InitStructure);
145
146 GPIO_InitStructure.GPIO_Pin = SDK_EVAL_I2C_DATA_PIN;
147 GPIO_InitStructure.GPIO_Mode = SDK_EVAL_I2C_DATA_MODE;
148 GPIO_Init(&GPIO_InitStructure);
149
150 /* Configure I2C in master mode */
151 I2C_StructInit(&I2C_InitStruct);
152 I2C_InitStruct.I2C_OperatingMode = I2C_OperatingMode_Master;
153 I2C_InitStruct.I2C_ClockSpeed = baudrate;
154 I2C_Init((I2C_Type*)SDK_EVAL_I2C, &I2C_InitStruct);
155
156 /* Clear all I2C pending interrupts */
157 I2C_ClearITPendingBit((I2C_Type*)SDK_EVAL_I2C, I2C_IT_MSK);
158
159 return SUCCESS;
160 }
161
162
171 ErrorStatus SdkEvalI2CWrite(uint8_t* pBuffer, uint8_t DeviceAddr, uint8_t RegisterAddr, uint8_t NumByteToWrite)
172 {
173 I2C_TransactionType t;
174
175 /* Write the slave address */
176 t.Operation = I2C_Operation_Write;
177 t.Address = DeviceAddr;
178 t.StartByte = I2C_StartByte_Disable;
179 t.AddressType = I2C_AddressType_7Bit;
180 t.StopCondition = I2C_StopCondition_Enable;
181 t.Length = 1+NumByteToWrite;
182
183 /* Flush the slave address */
184 I2C_FlushTx((I2C_Type*)SDK_EVAL_I2C);
185 while (I2C_WaitFlushTx((I2C_Type*)SDK_EVAL_I2C) == I2C_OP_ONGOING);
186
187 /* Begin transaction */
188 I2C_BeginTransaction((I2C_Type*)SDK_EVAL_I2C, &t);
189
190 /* Fill TX FIFO with data to write */
191 I2C_FillTxFIFO((I2C_Type*)SDK_EVAL_I2C, RegisterAddr);
192
193 for(uint8_t i=0; i<NumByteToWrite;i++) {
194 I2C_FillTxFIFO((I2C_Type*)SDK_EVAL_I2C, pBuffer[i]);
195 }
196
197 /* Wait loop */
198 do {
199 if(I2C_GetStatus((I2C_Type*)SDK_EVAL_I2C) == I2C_OP_ABORTED)
200 return ERROR;
201
202 } while (I2C_GetITStatus((I2C_Type*)SDK_EVAL_I2C, I2C_IT_MTD) == RESET);
203
204 /* Clear pending bits */
205 I2C_ClearITPendingBit((I2C_Type*)SDK_EVAL_I2C, I2C_IT_MTD | I2C_IT_MTDWS);
206
207 return SUCCESS;
208 }
209
210
219 ErrorStatus SdkEvalI2CRead(uint8_t* pBuffer, uint8_t DeviceAddr, uint8_t RegisterAddr, uint8_t NumByteToRead)
220 {
221 I2C_TransactionType t;
222
223 /* Write the slave address */
224 t.Operation = I2C_Operation_Write;
225 t.Address = DeviceAddr;
226 t.StartByte = I2C_StartByte_Disable;
227 t.AddressType = I2C_AddressType_7Bit;
228 t.StopCondition = I2C_StopCondition_Disable;
229 t.Length = 1;
230
231 /* Flush the slave address */
232 I2C_FlushTx((I2C_Type*)SDK_EVAL_I2C);
233 while (I2C_WaitFlushTx((I2C_Type*)SDK_EVAL_I2C) == I2C_OP_ONGOING);
234
235 /* Begin transaction */
236 I2C_BeginTransaction((I2C_Type*)SDK_EVAL_I2C, &t);
237
238 /* Fill TX FIFO with data to write */
239 I2C_FillTxFIFO((I2C_Type*)SDK_EVAL_I2C, RegisterAddr);
240
241 /* Wait loop */
242 do {
243 if(I2C_GetStatus((I2C_Type*)SDK_EVAL_I2C) == I2C_OP_ABORTED)
244 return ERROR;
245
246 } while (I2C_GetITStatus((I2C_Type*)SDK_EVAL_I2C, I2C_IT_MTDWS) == RESET);
247
248 /* Clear pending bits */
249 I2C_ClearITPendingBit((I2C_Type*)SDK_EVAL_I2C, I2C_IT_MTDWS);
250
251 /* read data */
252 t.Operation = I2C_Operation_Read;
253 t.Address = DeviceAddr;
254 t.StartByte = I2C_StartByte_Disable;
255 t.AddressType = I2C_AddressType_7Bit;
256 t.StopCondition = I2C_StopCondition_Enable;
257 t.Length = NumByteToRead;
258 I2C_BeginTransaction((I2C_Type*)SDK_EVAL_I2C, &t);
259
260 /* Wait loop */
261 do {
262 if(I2C_OP_ABORTED == I2C_GetStatus((I2C_Type*)SDK_EVAL_I2C))
263 return ERROR;
264
265 } while (RESET == I2C_GetITStatus((I2C_Type*)SDK_EVAL_I2C, I2C_IT_MTD));
266
267 /* Clear pending bits */
268 I2C_ClearITPendingBit((I2C_Type*)SDK_EVAL_I2C, I2C_IT_MTD | I2C_IT_MTDWS);
269
270 /* Get data from RX FIFO */
271 while(NumByteToRead--) {
272 *pBuffer = I2C_ReceiveData((I2C_Type*)SDK_EVAL_I2C);
273 pBuffer ++;
274 }
275
276 return SUCCESS;
277 }
278
279
280
281
282
288 ErrorStatus SdkEvalI2CDmaInit(uint32_t baudrate)
289 {
290 GPIO_InitType GPIO_InitStructure;
291 I2C_InitType I2C_InitStruct;
292 DMA_InitType DMA_InitStructure;
293 NVIC_InitType NVIC_InitStructure;
294
295 /* Enable I2C and GPIO clocks */
296 if(SDK_EVAL_I2C == I2C2) {
297 SysCtrl_PeripheralClockCmd(CLOCK_PERIPH_GPIO | CLOCK_PERIPH_I2C2 | CLOCK_PERIPH_DMA, ENABLE);
298 }
299 else {
300 SysCtrl_PeripheralClockCmd(CLOCK_PERIPH_GPIO | CLOCK_PERIPH_I2C1 | CLOCK_PERIPH_DMA, ENABLE);
301 }
302
303 /* Configure I2C pins */
304 GPIO_InitStructure.GPIO_Pin = SDK_EVAL_I2C_CLK_PIN ;
305 GPIO_InitStructure.GPIO_Mode = SDK_EVAL_I2C_CLK_MODE;
306 GPIO_InitStructure.GPIO_Pull = DISABLE;
307 GPIO_InitStructure.GPIO_HighPwr = DISABLE;
308 GPIO_Init(&GPIO_InitStructure);
309
310 GPIO_InitStructure.GPIO_Pin = SDK_EVAL_I2C_DATA_PIN;
311 GPIO_InitStructure.GPIO_Mode = SDK_EVAL_I2C_DATA_MODE;
312 GPIO_Init(&GPIO_InitStructure);
313
314 /* Configure I2C in master mode */
315 I2C_StructInit(&I2C_InitStruct);
316 I2C_InitStruct.I2C_OperatingMode = I2C_OperatingMode_Master;
317 I2C_InitStruct.I2C_ClockSpeed = baudrate;
318 I2C_Init((I2C_Type*)SDK_EVAL_I2C, &I2C_InitStruct);
319
320 /* Clear all I2C pending interrupts */
321 I2C_ClearITPendingBit((I2C_Type*)SDK_EVAL_I2C, I2C_IT_MSK);
322
323 /* Configure DMA I2C TX channel */
324 DMA_InitStructure.DMA_PeripheralBaseAddr = I2C_TX_DR_BASE_ADDR;
325 DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)i2c_buffer_tx;
326 DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST;
327 DMA_InitStructure.DMA_BufferSize = (uint32_t)I2C_BUFF_SIZE;
328 DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
329 DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
330 DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;
331 DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;
332 DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;
333 DMA_InitStructure.DMA_Priority = DMA_Priority_Medium;
334 DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
335 DMA_Init((DMA_CH_Type*)DMA_CH_I2C_TX, &DMA_InitStructure);
336
337 /* Configure DMA I2C RX channel */
338 DMA_InitStructure.DMA_PeripheralBaseAddr = I2C_RX_DR_BASE_ADDR;
339 DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)i2c_buffer_rx;
340 DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
341 DMA_InitStructure.DMA_BufferSize = (uint32_t)I2C_BUFF_SIZE;
342 DMA_Init((DMA_CH_Type*)DMA_CH_I2C_RX, &DMA_InitStructure);
343
344 /* Enable DMA_CH_I2C_RX Transfer Complete interrupt */
345 DMA_FlagConfig((DMA_CH_Type*)DMA_CH_I2C_RX, DMA_FLAG_TC, ENABLE);
346 DMA_FlagConfig((DMA_CH_Type*)DMA_CH_I2C_TX, DMA_FLAG_TC, ENABLE);
347
348 /* Enable the DMA Interrupt */
349 NVIC_InitStructure.NVIC_IRQChannel = DMA_IRQn;
350 NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = HIGH_PRIORITY;
351 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
352 NVIC_Init(&NVIC_InitStructure);
353
354 return SUCCESS;
355 }
356
357
366 ErrorStatus SdkEvalI2CDmaWrite(uint8_t* pBuffer, uint8_t DeviceAddr, uint8_t RegisterAddr, uint8_t NumByteToWrite)
367 {
368 I2C_TransactionType t;
369
370 /* Write the slave address */
371 t.Operation = I2C_Operation_Write;
372 t.Address = DeviceAddr;
373 t.StartByte = I2C_StartByte_Disable;
374 t.AddressType = I2C_AddressType_7Bit;
375 t.StopCondition = I2C_StopCondition_Enable;
376 t.Length = 1 + NumByteToWrite;
377
378 /* Fill TX FIFO with data to write */
379 i2c_buffer_tx[0] = RegisterAddr;
380 for(uint8_t i=0; i<NumByteToWrite;i++) {
381 i2c_buffer_tx[i+1] = pBuffer[i];
382 }
383
384 while(i2c_eot==RESET);
385 i2c_eot = RESET;
386
387 /* Clear pending bits */
388 I2C_ClearITPendingBit((I2C_Type*)SDK_EVAL_I2C, I2C_IT_MTDWS);
389
390 /* Flush the slave address */
391 I2C_FlushTx((I2C_Type*)SDK_EVAL_I2C);
392 while (I2C_WaitFlushTx((I2C_Type*)SDK_EVAL_I2C) == I2C_OP_ONGOING);
393
394 /* Enable I2C_TX/I2C_RX DMA requests */
395 I2C_DMACmd((I2C_Type*)SDK_EVAL_I2C, I2C_DMAReq_Tx, ENABLE);
396
397 /* Reset DMA_CH_UART_TX remaining bytes register */
398 ((DMA_CH_Type*)DMA_CH_I2C_TX)->CNDTR = NumByteToWrite + 1;
399
400 /* Begin transaction */
401 I2C_BeginTransaction((I2C_Type*)SDK_EVAL_I2C, &t);
402
403 /* DMA_CH_UART_TX enable */
404 ((DMA_CH_Type*)DMA_CH_I2C_TX)->CCR_b.EN = SET;
405
406 /* Wait loop IT IS REALLY NECESSARY, SHOULD BE REMOVED */
407 while (I2C_GetITStatus((I2C_Type*)SDK_EVAL_I2C, I2C_IT_MTDWS) == RESET);
408
409 return SUCCESS;
410 }
411
412
421 ErrorStatus SdkEvalI2CDmaRead(uint8_t* pBuffer, uint8_t DeviceAddr, uint8_t RegisterAddr, uint8_t NumByteToRead)
422 {
423 I2C_TransactionType t;
424
425 /* Write the slave address */
426 t.Operation = I2C_Operation_Write;
427 t.Address = DeviceAddr;
428 t.StartByte = I2C_StartByte_Disable;
429 t.AddressType = I2C_AddressType_7Bit;
430 t.StopCondition = I2C_StopCondition_Disable;
431 t.Length = 1;
432
433 /* Fill TX FIFO with data to write */
434 i2c_buffer_tx[0] = RegisterAddr;
435
436 while(i2c_eot==RESET);
437 i2c_eot = RESET;
438
439 /* Clear pending bits */
440 I2C_ClearITPendingBit((I2C_Type*)SDK_EVAL_I2C, I2C_IT_MTDWS);
441
442 /* Enable I2C_TX/I2C_RX DMA requests */
443 I2C_DMACmd((I2C_Type*)SDK_EVAL_I2C, I2C_DMAReq_Tx, ENABLE);
444
445 /* Reset DMA_CH_UART_TX remaining bytes register */
446 ((DMA_CH_Type*)DMA_CH_I2C_TX)->CNDTR = 1;
447
448 /* Flush the slave address */
449 I2C_FlushTx((I2C_Type*)SDK_EVAL_I2C);
450 while (I2C_WaitFlushTx((I2C_Type*)SDK_EVAL_I2C) == I2C_OP_ONGOING);
451
452 /* Begin transaction */
453 I2C_BeginTransaction((I2C_Type*)SDK_EVAL_I2C, &t);
454
455 /* DMA_CH_UART_TX enable */
456 ((DMA_CH_Type*)DMA_CH_I2C_TX)->CCR_b.EN = SET;
457
458 while(i2c_eot==RESET);
459 i2c_eot = RESET;
460
461 /* Wait loop IT IS REALLY NECESSARY, SHOULD BE REMOVED */
462 while (I2C_GetITStatus((I2C_Type*)SDK_EVAL_I2C, I2C_IT_MTDWS) == RESET);
463
464 /* Clear pending bits */
465 I2C_ClearITPendingBit((I2C_Type*)SDK_EVAL_I2C, I2C_IT_MTDWS);
466
467
468 /* read data */
469 t.Operation = I2C_Operation_Read;
470 t.Address = DeviceAddr;
471 t.StartByte = I2C_StartByte_Disable;
472 t.AddressType = I2C_AddressType_7Bit;
473 t.StopCondition = I2C_StopCondition_Enable;
474 t.Length = NumByteToRead;
475
476 /* DMA RX channel request enable */
477 I2C_DMACmd((I2C_Type*)SDK_EVAL_I2C, I2C_DMAReq_Rx, ENABLE);
478
479 /* Reset DMA_CH_UART_TX remaining bytes register */
480 ((DMA_CH_Type*)DMA_CH_I2C_RX)->CNDTR = NumByteToRead;
481
482 /* DMA_CH_UART_TX enable */
483 ((DMA_CH_Type*)DMA_CH_I2C_RX)->CCR_b.EN = SET;
484
485 I2C_BeginTransaction((I2C_Type*)SDK_EVAL_I2C, &t);
486
487 while(i2c_eot==RESET);
488
489 /* Get data from RX FIFO */
490 for(uint8_t i=0;i<NumByteToRead;i++) {
491 pBuffer[i] = i2c_buffer_rx[i];
492 }
493
494 return SUCCESS;
495 }
496
497
503 void DmaI2CHandlerCallback(void)
504 {
505 /* Check DMA_CH_I2C_RX_IT_TC */
506 if(DMA_GetFlagStatus(DMA_CH_I2C_RX_IT_TC)) {
507
508 /* Clear pending bit */
509 DMA_ClearFlag(DMA_CH_I2C_RX_IT_TC);
510
511 /* DMA_I2C_TX/RX disable */
512 ((DMA_CH_Type*)DMA_CH_I2C_RX)->CCR_b.EN = RESET;
513
514 /* Set the i2c_eot flag */
515 i2c_eot = SET;
516 }
517
518 /* Check DMA_CH_I2C_TX_IT_TC */
519 if(DMA_GetFlagStatus(DMA_CH_I2C_TX_IT_TC)) {
520
521 /* Clear pending bit */
522 DMA_ClearFlag(DMA_CH_I2C_TX_IT_TC);
523
524 /* DMA_I2C_TX/RX disable */
525 ((DMA_CH_Type*)DMA_CH_I2C_TX)->CCR_b.EN = RESET;
526
527 /* Set the i2c_eot flag */
528 i2c_eot = SET;
529 }
530 }
531
532
533
534
540 ErrorStatus SdkEvalI2CIrqInit(uint32_t baudrate)
541 {
542 GPIO_InitType GPIO_InitStructure;
543 I2C_InitType I2C_InitStruct;
544 NVIC_InitType NVIC_InitStructure;
545
546 /* Enable I2C and GPIO clocks */
547 if(SDK_EVAL_I2C == I2C2) {
548 SysCtrl_PeripheralClockCmd(CLOCK_PERIPH_GPIO | CLOCK_PERIPH_I2C2, ENABLE);
549 }
550 else {
551 SysCtrl_PeripheralClockCmd(CLOCK_PERIPH_GPIO | CLOCK_PERIPH_I2C1, ENABLE);
552 }
553
554 /* Configure I2C pins */
555 GPIO_InitStructure.GPIO_Pin = SDK_EVAL_I2C_CLK_PIN ;
556 GPIO_InitStructure.GPIO_Mode = SDK_EVAL_I2C_CLK_MODE;
557 GPIO_InitStructure.GPIO_Pull = DISABLE;
558 GPIO_InitStructure.GPIO_HighPwr = DISABLE;
559 GPIO_Init(&GPIO_InitStructure);
560
561 GPIO_InitStructure.GPIO_Pin = SDK_EVAL_I2C_DATA_PIN;
562 GPIO_InitStructure.GPIO_Mode = SDK_EVAL_I2C_DATA_MODE;
563 GPIO_Init(&GPIO_InitStructure);
564
565 /* Configure I2C in master mode */
566 I2C_StructInit(&I2C_InitStruct);
567 I2C_InitStruct.I2C_OperatingMode = I2C_OperatingMode_Master;
568 I2C_InitStruct.I2C_ClockSpeed = baudrate;
569 I2C_Init((I2C_Type*)SDK_EVAL_I2C, &I2C_InitStruct);
570
571 /* Configure the interrupt source */
572 I2C_ITConfig((I2C_Type*)SDK_EVAL_I2C, I2C_IT_MTDWS , ENABLE);
573
574 /* Enable the DMA Interrupt */
575 NVIC_InitStructure.NVIC_IRQChannel = I2C2_IRQn; /* DA SISTEMARE COL TIPO SDK_EVAL_CONFIG */
576 NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = MED_PRIORITY;
577 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
578 NVIC_Init(&NVIC_InitStructure);
579
580 /* Clear all I2C pending interrupts */
581 I2C_ClearITPendingBit((I2C_Type*)SDK_EVAL_I2C, I2C_IT_MSK);
582
583 return SUCCESS;
584 }
585
586
595 ErrorStatus SdkEvalI2CIrqWrite(uint8_t* pBuffer, uint8_t DeviceAddr, uint8_t RegisterAddr, uint8_t NumByteToWrite)
596 {
597 I2C_TransactionType t;
598
599 /* Write the slave address */
600 t.Operation = I2C_Operation_Write;
601 t.Address = DeviceAddr;
602 t.StartByte = I2C_StartByte_Disable;
603 t.AddressType = I2C_AddressType_7Bit;
604 t.StopCondition = I2C_StopCondition_Enable;
605 t.Length = 1+NumByteToWrite;
606
607 /* Flush the slave address */
608 I2C_FlushTx((I2C_Type*)SDK_EVAL_I2C);
609 while (I2C_WaitFlushTx((I2C_Type*)SDK_EVAL_I2C) == I2C_OP_ONGOING);
610
611 /* Begin transaction */
612 i2c_eot = RESET;
613 I2C_BeginTransaction((I2C_Type*)SDK_EVAL_I2C, &t);
614
615 /* Fill TX FIFO with data to write */
616 I2C_FillTxFIFO((I2C_Type*)SDK_EVAL_I2C, RegisterAddr);
617
618 for(uint8_t i=0; i<NumByteToWrite;i++) {
619 I2C_FillTxFIFO((I2C_Type*)SDK_EVAL_I2C, pBuffer[i]);
620 }
621
622 /* Wait loop */
623 while(i2c_eot == RESET);
624
625 return SUCCESS;
626 }
627
628
637 ErrorStatus SdkEvalI2CIrqRead(uint8_t* pBuffer, uint8_t DeviceAddr, uint8_t RegisterAddr, uint8_t NumByteToRead)
638 {
639 I2C_TransactionType t;
640
641 /* Write the slave address */
642 t.Operation = I2C_Operation_Write;
643 t.Address = DeviceAddr;
644 t.StartByte = I2C_StartByte_Disable;
645 t.AddressType = I2C_AddressType_7Bit;
646 t.StopCondition = I2C_StopCondition_Disable;
647 t.Length = 1;
648
649 /* Flush the slave address */
650 I2C_FlushTx((I2C_Type*)SDK_EVAL_I2C);
651 while (I2C_WaitFlushTx((I2C_Type*)SDK_EVAL_I2C) == I2C_OP_ONGOING);
652
653 /* Begin transaction */
654 i2c_eot = RESET;
655 I2C_BeginTransaction((I2C_Type*)SDK_EVAL_I2C, &t);
656
657 /* Fill TX FIFO with data to write */
658 I2C_FillTxFIFO((I2C_Type*)SDK_EVAL_I2C, RegisterAddr);
659
660 /* Wait loop */
661 while(i2c_eot == RESET);
662
663 /* read data */
664 t.Operation = I2C_Operation_Read;
665 t.Address = DeviceAddr;
666 t.StartByte = I2C_StartByte_Disable;
667 t.AddressType = I2C_AddressType_7Bit;
668 t.StopCondition = I2C_StopCondition_Enable;
669 t.Length = NumByteToRead;
670
671 /* Begin transaction */
672 i2c_eot = RESET;
673 I2C_BeginTransaction((I2C_Type*)SDK_EVAL_I2C, &t);
674
675 /* Wait loop */
676 while(i2c_eot == RESET);
677
678 /* Get data from RX FIFO */
679 while(NumByteToRead--) {
680 *pBuffer = I2C_ReceiveData((I2C_Type*)SDK_EVAL_I2C);
681 pBuffer ++;
682 }
683
684 return SUCCESS;
685 }
686
687
688
694 void IrqI2CHandlerCallback(void)
695 {
696 /* Check DMA_CH_I2C_RX_IT_TC */
697 if(I2C_GetITStatus((I2C_Type*)SDK_EVAL_I2C, I2C_IT_MTDWS))
698 {
699 I2C_ClearITPendingBit((I2C_Type*)SDK_EVAL_I2C, I2C_IT_MTD | I2C_IT_MTDWS);
700
701 /* Set the i2c_eot flag */
702 i2c_eot = SET;
703 }
704
705 }
706
722 /******************* (C) COPYRIGHT 2015 STMicroelectronics *****END OF FILE****/
SDK_EVAL_I2C_CLK_MODE
#define SDK_EVAL_I2C_CLK_MODE
Definition: USER_Platform_Configuration.h:62
i2c_buffer_rx
uint8_t i2c_buffer_rx[I2C_BUFF_SIZE]
Definition: SDK_EVAL_I2C.c:80
IrqI2CHandlerCallback
void IrqI2CHandlerCallback(void)
I2C DMA ISR callback function.
Definition: SDK_EVAL_I2C.c:694
SdkEvalI2CDmaWrite
ErrorStatus SdkEvalI2CDmaWrite(uint8_t *pBuffer, uint8_t DeviceAddr, uint8_t RegisterAddr, uint8_t NumByteToWrite)
I2C function to write registers of a slave device.
Definition: SDK_EVAL_I2C.c:366
SdkEvalI2CIrqRead
ErrorStatus SdkEvalI2CIrqRead(uint8_t *pBuffer, uint8_t DeviceAddr, uint8_t RegisterAddr, uint8_t NumByteToRead)
I2C function to read registers from a slave device.
Definition: SDK_EVAL_I2C.c:637
SdkEvalI2CInit
ErrorStatus SdkEvalI2CInit(uint32_t baudrate)
Configures I2C interface.
Definition: SDK_EVAL_I2C.c:126
DMA_CH_I2C_RX_IT_TC
#define DMA_CH_I2C_RX_IT_TC
I2C_RX DMA Transfer Complete Interrupt.
Definition: SDK_EVAL_I2C.h:82
DmaI2CHandlerCallback
void DmaI2CHandlerCallback(void)
I2C DMA ISR callback function.
Definition: SDK_EVAL_I2C.c:503
DMA_CH_I2C_TX
#define DMA_CH_I2C_TX
I2C_TX DMA channel.
Definition: SDK_EVAL_I2C.h:67
SDK_EVAL_I2C_CLK_PIN
#define SDK_EVAL_I2C_CLK_PIN
Definition: USER_Platform_Configuration.h:61
I2C_TX_DR_BASE_ADDR
#define I2C_TX_DR_BASE_ADDR
I2C DR address.
Definition: SDK_EVAL_I2C.c:53
i2c_buffer_tx
uint8_t i2c_buffer_tx[I2C_BUFF_SIZE]
I2C buffers used for DMA application.
Definition: SDK_EVAL_I2C.c:79
SDK_EVAL_I2C_DATA_MODE
#define SDK_EVAL_I2C_DATA_MODE
Definition: USER_Platform_Configuration.h:59
SDK_EVAL_I2C_DATA_PIN
#define SDK_EVAL_I2C_DATA_PIN
Definition: USER_Platform_Configuration.h:58
SDK_EVAL_I2C
#define SDK_EVAL_I2C
BlueNRG1 Eval Board (STEVAL-IDB007Vx) I2C definitions.
Definition: USER_Platform_Configuration.h:56
i2c_eot
volatile FlagStatus i2c_eot
I2C flag set at end of transaction.
Definition: SDK_EVAL_I2C.c:85
SdkEvalI2CRead
ErrorStatus SdkEvalI2CRead(uint8_t *pBuffer, uint8_t DeviceAddr, uint8_t RegisterAddr, uint8_t NumByteToRead)
I2C function to read registers from a slave device.
Definition: SDK_EVAL_I2C.c:219
SdkEvalI2CWrite
ErrorStatus SdkEvalI2CWrite(uint8_t *pBuffer, uint8_t DeviceAddr, uint8_t RegisterAddr, uint8_t NumByteToWrite)
I2C function to write registers of a slave device.
Definition: SDK_EVAL_I2C.c:171
SdkEvalI2CDmaInit
ErrorStatus SdkEvalI2CDmaInit(uint32_t baudrate)
Configures I2C interface and the I2C_TX/I2C_RX DMA channels.
Definition: SDK_EVAL_I2C.c:288
SDK_EVAL_I2C.h
This file provides all the low level API to manage I2C interface for eval board.
DMA_CH_I2C_RX
#define DMA_CH_I2C_RX
I2C_RX DMA channel.
Definition: SDK_EVAL_I2C.h:77
I2C_BUFF_SIZE
#define I2C_BUFF_SIZE
I2C buffer max size.
Definition: SDK_EVAL_I2C.h:62
SdkEvalI2CIrqInit
ErrorStatus SdkEvalI2CIrqInit(uint32_t baudrate)
Configures I2C interface.
Definition: SDK_EVAL_I2C.c:540
SdkEvalI2CDmaRead
ErrorStatus SdkEvalI2CDmaRead(uint8_t *pBuffer, uint8_t DeviceAddr, uint8_t RegisterAddr, uint8_t NumByteToRead)
I2C function to read registers from a slave device.
Definition: SDK_EVAL_I2C.c:421
I2C_RX_DR_BASE_ADDR
#define I2C_RX_DR_BASE_ADDR
Definition: SDK_EVAL_I2C.c:55
DMA_CH_I2C_TX_IT_TC
#define DMA_CH_I2C_TX_IT_TC
I2C_TX DMA Transfer Complete Interrupt.
Definition: SDK_EVAL_I2C.h:72
SdkEvalI2CIrqWrite
ErrorStatus SdkEvalI2CIrqWrite(uint8_t *pBuffer, uint8_t DeviceAddr, uint8_t RegisterAddr, uint8_t NumByteToWrite)
I2C function to write registers of a slave device.
Definition: SDK_EVAL_I2C.c:595