1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
27
28
29
30
33
34
37
38
39
40
41
44
45
49
50
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
71
72
73
74
80
81
82
83
84
85
86
87
88
89
90
91
92
95
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
185
190
191
192
193
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
302
303
304
305
309
310
311
312
313
314
315
316
317
321
322
323
324
325
326
327
328
329
330
331
332
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
395
396
397
398
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
421
422
423
424
425
426
427
428
429
430
431
432
433
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
483
484
485
486
487
492
501
502
503
504
505
506
507
508
509
510
525
526
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
551
556
557
562
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
588
589
590
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
621
622
632
633
640
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
879
880
881
882
883
884
885
886
889
890
891
892
893
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
915
920
921
927
943
944
950
951
952
954
955
956
957
963
969
970
971
978
985
986
992
997
998
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1043
1044
1045
1048
1049
1050
1051
1054
1055
/* ... */
#if defined(__GNUC__)
#include <stdio.h>
#include <stdlib.h>
/* ... */#endif
#include "main.h"
/* ... */
/* ... */
Includes
/* ... */
#if (USE_TIMEOUT == 1)
#define DMA_SEND_TIMEOUT_TC_MS 5
#define I2C_SEND_TIMEOUT_TC_MS 2
#define I2C_SEND_TIMEOUT_STOP_MS 5
/* ... */#endif
/* ... */
#define I2C_SPEEDCLOCK 400000
#define I2C_DUTYCYCLE LL_I2C_DUTYCYCLE_2
#define SLAVE_CHIP_NAME 0
#define SLAVE_CHIP_REVISION 1
Private define
#if (USE_TIMEOUT == 1)
uint32_t Timeout = 0;
#endif
__IO uint8_t ubButtonPress = 0;
/* ... */
const char* aCommandCode[4][4] = {
{"CHIP NAME", "YES"},
{"CHIP REVISION", "YES"},
{"LOW POWER", "NO"},
{"WAKE UP", "NO"}
...};
__IO uint8_t ubMasterXferDirection = 0;
__IO uint8_t ubMasterRequestDirection = 0;
uint32_t* pMasterTransmitBuffer = (uint32_t*)(&aCommandCode[0][0]);
uint8_t ubMasterNbCommandCode = sizeof(aCommandCode[0][0]);
uint8_t aMasterReceiveBuffer[0xF] = {0};
__IO uint8_t ubMasterNbDataToReceive = sizeof(aMasterReceiveBuffer);
__IO uint8_t ubMasterNbDataToTransmit = 0;
uint8_t ubMasterCommandIndex = 0;
__IO uint8_t ubMasterReceiveIndex = 0;
__IO uint8_t ubMasterTransferComplete = 0;
/* ... */
const char* aSlaveInfo[] = {
"STM32F411xx",
"1.2.3"...};
uint8_t aSlaveReceiveBuffer[0xF] = {0};
uint8_t* pSlaveTransmitBuffer = 0;
__IO uint8_t ubSlaveNbDataToTransmit = 0;
uint8_t ubSlaveInfoIndex = 0xFF;
__IO uint8_t ubSlaveReceiveIndex = 0;
__IO uint8_t ubSlaveReceiveComplete = 0;
Private variables
void SystemClock_Config(void);
void Configure_DMA(void);
void Configure_I2C_Slave(void);
void Configure_I2C_Master(void);
void Activate_I2C_Slave(void);
void Activate_I2C_Master(void);
uint8_t Buffercmp8(uint8_t* pBuffer1, uint8_t* pBuffer2, uint8_t BufferLength);
void FlushBuffer8(uint8_t* pBuffer1);
void LED_Init(void);
void LED_On(void);
void LED_Off(void);
void LED_Blinking(uint32_t Period);
void WaitForUserButtonPress(void);
void Handle_I2C_Slave(void);
void Handle_I2C_Master_Transmit(void);
void Handle_I2C_Master_TransmitReceive(void);
void UserButton_Init(void);
#if defined(__GNUC__)
extern void initialise_monitor_handles(void);
#endif
Private function prototypes
/* ... */
int main(void)
{
#if defined(__GNUC__)
initialise_monitor_handles();
#endif
SystemClock_Config();
LED_Init();
LED_Off();
UserButton_Init();
Configure_DMA();
Configure_I2C_Slave();
Configure_I2C_Master();
Activate_I2C_Slave();
Activate_I2C_Master();
while (1)
{
WaitForUserButtonPress();
Handle_I2C_Slave();
ubButtonPress = 0;
if(strncmp(aCommandCode[ubMasterCommandIndex][1], "NO", 2) == 0)
{
Handle_I2C_Master_Transmit();
}if (strncmp(aCommandCode[ubMasterCommandIndex][1], "NO", 2) == 0) { ... }
else
{
Handle_I2C_Master_TransmitReceive();
}else { ... }
ubMasterCommandIndex++;
if(ubMasterCommandIndex >= ubMasterNbCommandCode)
{
ubMasterCommandIndex = 0;
}if (ubMasterCommandIndex >= ubMasterNbCommandCode) { ... }
}while (1) { ... }
}{ ... }
/* ... */
void Configure_DMA(void)
{
LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_DMA1);
NVIC_SetPriority(DMA1_Stream5_IRQn, 0x4);
NVIC_EnableIRQ(DMA1_Stream5_IRQn);
NVIC_SetPriority(DMA1_Stream2_IRQn, 0x1);
NVIC_EnableIRQ(DMA1_Stream2_IRQn);
LL_DMA_SetChannelSelection(DMA1, LL_DMA_STREAM_5, LL_DMA_CHANNEL_6);
LL_DMA_ConfigTransfer(DMA1, LL_DMA_STREAM_5, LL_DMA_DIRECTION_MEMORY_TO_PERIPH | \
LL_DMA_PRIORITY_HIGH | \
LL_DMA_MODE_NORMAL | \
LL_DMA_PERIPH_NOINCREMENT | \
LL_DMA_MEMORY_INCREMENT | \
LL_DMA_PDATAALIGN_BYTE | \
LL_DMA_MDATAALIGN_BYTE);
LL_DMA_ConfigAddresses(DMA1, LL_DMA_STREAM_5, (uint32_t)(*pMasterTransmitBuffer), (uint32_t)LL_I2C_DMA_GetRegAddr(I2C3), LL_DMA_GetDataTransferDirection(DMA1, LL_DMA_STREAM_5));
LL_DMA_SetChannelSelection(DMA1, LL_DMA_STREAM_2, LL_DMA_CHANNEL_3);
LL_DMA_ConfigTransfer(DMA1, LL_DMA_STREAM_2, LL_DMA_DIRECTION_PERIPH_TO_MEMORY | \
LL_DMA_PRIORITY_HIGH | \
LL_DMA_MODE_NORMAL | \
LL_DMA_PERIPH_NOINCREMENT | \
LL_DMA_MEMORY_INCREMENT | \
LL_DMA_PDATAALIGN_BYTE | \
LL_DMA_MDATAALIGN_BYTE);
LL_DMA_ConfigAddresses(DMA1, LL_DMA_STREAM_2, (uint32_t)LL_I2C_DMA_GetRegAddr(I2C3), (uint32_t)&(aMasterReceiveBuffer), LL_DMA_GetDataTransferDirection(DMA1, LL_DMA_STREAM_2));
LL_DMA_EnableIT_TC(DMA1, LL_DMA_STREAM_5);
LL_DMA_EnableIT_TE(DMA1, LL_DMA_STREAM_5);
LL_DMA_EnableIT_TC(DMA1, LL_DMA_STREAM_2);
LL_DMA_EnableIT_TE(DMA1, LL_DMA_STREAM_2);
}{ ... }
/* ... */
void Configure_I2C_Slave(void)
{
LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPIOB);
LL_GPIO_SetPinMode(GPIOB, LL_GPIO_PIN_6, LL_GPIO_MODE_ALTERNATE);
LL_GPIO_SetAFPin_0_7(GPIOB, LL_GPIO_PIN_6, LL_GPIO_AF_4);
LL_GPIO_SetPinSpeed(GPIOB, LL_GPIO_PIN_6, LL_GPIO_SPEED_FREQ_HIGH);
LL_GPIO_SetPinOutputType(GPIOB, LL_GPIO_PIN_6, LL_GPIO_OUTPUT_OPENDRAIN);
LL_GPIO_SetPinPull(GPIOB, LL_GPIO_PIN_6, LL_GPIO_PULL_UP);
LL_GPIO_SetPinMode(GPIOB, LL_GPIO_PIN_7, LL_GPIO_MODE_ALTERNATE);
LL_GPIO_SetAFPin_0_7(GPIOB, LL_GPIO_PIN_7, LL_GPIO_AF_4);
LL_GPIO_SetPinSpeed(GPIOB, LL_GPIO_PIN_7, LL_GPIO_SPEED_FREQ_HIGH);
LL_GPIO_SetPinOutputType(GPIOB, LL_GPIO_PIN_7, LL_GPIO_OUTPUT_OPENDRAIN);
LL_GPIO_SetPinPull(GPIOB, LL_GPIO_PIN_7, LL_GPIO_PULL_UP);
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_I2C1);
/* ... */
NVIC_SetPriority(I2C1_EV_IRQn, 0xF);
NVIC_EnableIRQ(I2C1_EV_IRQn);
/* ... */
NVIC_SetPriority(I2C1_ER_IRQn, 0xF);
NVIC_EnableIRQ(I2C1_ER_IRQn);
LL_I2C_Disable(I2C1);
/* ... */
LL_I2C_SetOwnAddress1(I2C1, SLAVE_OWN_ADDRESS, LL_I2C_OWNADDRESS1_7BIT);
/* ... */
}{ ... }
/* ... */
void Configure_I2C_Master(void)
{
LL_RCC_ClocksTypeDef rcc_clocks;
LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPIOA);
LL_GPIO_SetPinMode(GPIOA, LL_GPIO_PIN_8, LL_GPIO_MODE_ALTERNATE);
LL_GPIO_SetAFPin_8_15(GPIOA, LL_GPIO_PIN_8, LL_GPIO_AF_4);
LL_GPIO_SetPinSpeed(GPIOA, LL_GPIO_PIN_8, LL_GPIO_SPEED_FREQ_HIGH);
LL_GPIO_SetPinOutputType(GPIOA, LL_GPIO_PIN_8, LL_GPIO_OUTPUT_OPENDRAIN);
LL_GPIO_SetPinPull(GPIOA, LL_GPIO_PIN_8, LL_GPIO_PULL_UP);
LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_GPIOB);
LL_GPIO_SetPinMode(GPIOB, LL_GPIO_PIN_4, LL_GPIO_MODE_ALTERNATE);
LL_GPIO_SetAFPin_0_7(GPIOB, LL_GPIO_PIN_4, LL_GPIO_AF_9);
LL_GPIO_SetPinSpeed(GPIOB, LL_GPIO_PIN_4, LL_GPIO_SPEED_FREQ_HIGH);
LL_GPIO_SetPinOutputType(GPIOB, LL_GPIO_PIN_4, LL_GPIO_OUTPUT_OPENDRAIN);
LL_GPIO_SetPinPull(GPIOB, LL_GPIO_PIN_4, LL_GPIO_PULL_UP);
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_I2C3);
/* ... */
NVIC_SetPriority(I2C3_EV_IRQn, 0);
NVIC_EnableIRQ(I2C3_EV_IRQn);
/* ... */
NVIC_SetPriority(I2C3_ER_IRQn, 0);
NVIC_EnableIRQ(I2C3_ER_IRQn);
LL_I2C_Disable(I2C3);
LL_RCC_GetSystemClocksFreq(&rcc_clocks);
LL_I2C_ConfigSpeed(I2C3, rcc_clocks.PCLK1_Frequency, I2C_SPEEDCLOCK, I2C_DUTYCYCLE);
/* ... */
/* ... */
}{ ... }
/* ... */
void Activate_I2C_Slave(void)
{
LL_I2C_Enable(I2C1);
/* ... */
LL_I2C_EnableIT_EVT(I2C1);
LL_I2C_EnableIT_ERR(I2C1);
}{ ... }
/* ... */
void Activate_I2C_Master(void)
{
LL_I2C_Enable(I2C3);
/* ... */
LL_I2C_EnableIT_EVT(I2C3);
LL_I2C_EnableIT_ERR(I2C3);
}{ ... }
/* ... */
void FlushBuffer8(uint8_t* pBuffer1)
{
uint8_t Index = 0;
for (Index = 0; Index < sizeof(pBuffer1); Index++)
{
pBuffer1[Index] = 0;
}for (Index = 0; Index < sizeof(pBuffer1); Index++) { ... }
}{ ... }
/* ... */
uint8_t Buffercmp8(uint8_t* pBuffer1, uint8_t* pBuffer2, uint8_t BufferLength)
{
while (BufferLength--)
{
if (*pBuffer1 != *pBuffer2)
{
return 1;
}if (*pBuffer1 != *pBuffer2) { ... }
pBuffer1++;
pBuffer2++;
}while (BufferLength--) { ... }
return 0;
}{ ... }
/* ... */
void LED_Init(void)
{
LED2_GPIO_CLK_ENABLE();
LL_GPIO_SetPinMode(LED2_GPIO_PORT, LED2_PIN, LL_GPIO_MODE_OUTPUT);
}{ ... }
/* ... */
void LED_On(void)
{
LL_GPIO_SetOutputPin(LED2_GPIO_PORT, LED2_PIN);
}{ ... }
/* ... */
void LED_Off(void)
{
LL_GPIO_ResetOutputPin(LED2_GPIO_PORT, LED2_PIN);
}{ ... }
/* ... */
void LED_Blinking(uint32_t Period)
{
LL_GPIO_SetOutputPin(LED2_GPIO_PORT, LED2_PIN);
while (1)
{
LL_GPIO_TogglePin(LED2_GPIO_PORT, LED2_PIN);
LL_mDelay(Period);
}while (1) { ... }
}{ ... }
/* ... */
void UserButton_Init(void)
{
USER_BUTTON_GPIO_CLK_ENABLE();
LL_GPIO_SetPinMode(USER_BUTTON_GPIO_PORT, USER_BUTTON_PIN, LL_GPIO_MODE_INPUT);
LL_GPIO_SetPinPull(USER_BUTTON_GPIO_PORT, USER_BUTTON_PIN, LL_GPIO_PULL_NO);
USER_BUTTON_SYSCFG_SET_EXTI();
USER_BUTTON_EXTI_LINE_ENABLE();
USER_BUTTON_EXTI_FALLING_TRIG_ENABLE();
NVIC_EnableIRQ(USER_BUTTON_EXTI_IRQn);
NVIC_SetPriority(USER_BUTTON_EXTI_IRQn, 0x03);
}{ ... }
/* ... */
void WaitForUserButtonPress(void)
{
while (ubButtonPress == 0)
{
LL_GPIO_TogglePin(LED2_GPIO_PORT, LED2_PIN);
LL_mDelay(LED_BLINK_FAST);
}while (ubButtonPress == 0) { ... }
LL_GPIO_ResetOutputPin(LED2_GPIO_PORT, LED2_PIN);
}{ ... }
/* ... */
void Handle_I2C_Slave(void)
{
LL_I2C_AcknowledgeNextData(I2C1, LL_I2C_ACK);
}{ ... }
/* ... */
void Handle_I2C_Master_Transmit(void)
{
pMasterTransmitBuffer = (uint32_t*)(&aCommandCode[ubMasterCommandIndex][0]);
ubMasterNbDataToTransmit = strlen((char *)pMasterTransmitBuffer[0]);
LL_DMA_SetMemoryAddress(DMA1, LL_DMA_STREAM_5, (uint32_t)(*pMasterTransmitBuffer));
LL_DMA_SetDataLength(DMA1, LL_DMA_STREAM_5, ubMasterNbDataToTransmit);
LL_DMA_EnableStream(DMA1, LL_DMA_STREAM_5);
LL_I2C_AcknowledgeNextData(I2C3, LL_I2C_ACK);
ubMasterRequestDirection = I2C_REQUEST_WRITE;
LL_I2C_GenerateStartCondition(I2C3);
#if (USE_TIMEOUT == 1)
Timeout = DMA_SEND_TIMEOUT_TC_MS;
#endif
while(!ubMasterTransferComplete)
{
#if (USE_TIMEOUT == 1)
if (LL_SYSTICK_IsActiveCounterFlag())
{
if(Timeout-- == 0)
{
LED_Blinking(LED_BLINK_SLOW);
}if (Timeout-- == 0) { ... }
}if (LL_SYSTICK_IsActiveCounterFlag()) { ... }
/* ... */#endif
}while (!ubMasterTransferComplete) { ... }
LL_I2C_GenerateStopCondition(I2C3);
LL_DMA_DisableStream(DMA1, LL_DMA_STREAM_5);
printf("%s : %s\n\r", (char*)(aCommandCode[ubMasterCommandIndex][0]), (char*)aMasterReceiveBuffer);
LED_On();
LL_mDelay(500);
LED_Off();
ubMasterTransferComplete = 0;
ubMasterNbDataToTransmit = 0;
ubMasterReceiveIndex = 0;
FlushBuffer8(aMasterReceiveBuffer);
}{ ... }
/* ... */
void Handle_I2C_Master_TransmitReceive(void)
{
pMasterTransmitBuffer = (uint32_t*)(&aCommandCode[ubMasterCommandIndex][0]);
ubMasterNbDataToTransmit = strlen((char *)pMasterTransmitBuffer[0]);
LL_DMA_SetMemoryAddress(DMA1, LL_DMA_STREAM_5, (uint32_t)(*pMasterTransmitBuffer));
LL_DMA_SetDataLength(DMA1, LL_DMA_STREAM_5, ubMasterNbDataToTransmit);
LL_DMA_EnableStream(DMA1, LL_DMA_STREAM_5);
LL_I2C_AcknowledgeNextData(I2C3, LL_I2C_ACK);
ubMasterRequestDirection = I2C_REQUEST_WRITE;
LL_I2C_GenerateStartCondition(I2C3);
#if (USE_TIMEOUT == 1)
Timeout = DMA_SEND_TIMEOUT_TC_MS;
#endif
while(!ubMasterTransferComplete)
{
#if (USE_TIMEOUT == 1)
if (LL_SYSTICK_IsActiveCounterFlag())
{
if(Timeout-- == 0)
{
LED_Blinking(LED_BLINK_SLOW);
}if (Timeout-- == 0) { ... }
}if (LL_SYSTICK_IsActiveCounterFlag()) { ... }
/* ... */#endif
}while (!ubMasterTransferComplete) { ... }
ubMasterTransferComplete = 0;
LL_DMA_DisableStream(DMA1, LL_DMA_STREAM_5);
LL_DMA_SetDataLength(DMA1, LL_DMA_STREAM_2, ubMasterNbDataToReceive);
LL_DMA_EnableStream(DMA1, LL_DMA_STREAM_2);
LL_I2C_AcknowledgeNextData(I2C3, LL_I2C_ACK);
ubMasterRequestDirection = I2C_REQUEST_READ;
LL_I2C_GenerateStartCondition(I2C3);
#if (USE_TIMEOUT == 1)
Timeout = DMA_SEND_TIMEOUT_TC_MS;
#endif
while(!ubMasterTransferComplete)
{
#if (USE_TIMEOUT == 1)
if (LL_SYSTICK_IsActiveCounterFlag())
{
if(Timeout-- == 0)
{
LED_Blinking(LED_BLINK_SLOW);
}if (Timeout-- == 0) { ... }
}if (LL_SYSTICK_IsActiveCounterFlag()) { ... }
/* ... */#endif
}while (!ubMasterTransferComplete) { ... }
LL_I2C_GenerateStopCondition(I2C2);
LL_I2C_DisableLastDMA(I2C2);
LL_I2C_AcknowledgeNextData(I2C2, LL_I2C_NACK);
LL_DMA_DisableStream(DMA1, LL_DMA_STREAM_2);
printf("%s : %s\n\r", (char*)(aCommandCode[ubMasterCommandIndex][0]), (char*)aMasterReceiveBuffer);
LED_On();
LL_mDelay(500);
LED_Off();
ubMasterTransferComplete = 0;
ubMasterNbDataToTransmit = 0;
ubMasterReceiveIndex = 0;
FlushBuffer8(aMasterReceiveBuffer);
}{ ... }
/* ... */
void SystemClock_Config(void)
{
LL_RCC_HSE_EnableBypass();
LL_RCC_HSE_Enable();
while(LL_RCC_HSE_IsReady() != 1)
{
}while (LL_RCC_HSE_IsReady() != 1) { ... };
LL_FLASH_SetLatency(LL_FLASH_LATENCY_3);
LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSE, LL_RCC_PLLM_DIV_8, 400, LL_RCC_PLLP_DIV_4);
LL_RCC_PLL_Enable();
while(LL_RCC_PLL_IsReady() != 1)
{
}while (LL_RCC_PLL_IsReady() != 1) { ... };
LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1);
LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL);
while(LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL)
{
}while (LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL) { ... };
LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_2);
LL_RCC_SetAPB2Prescaler(LL_RCC_APB2_DIV_1);
SysTick_Config(100000000 / 1000);
SystemCoreClock = 100000000;
}{ ... }
/* ... */
void UserButton_Callback(void)
{
ubButtonPress = 1;
}{ ... }
/* ... */
void Slave_Ready_To_Transmit_Callback(void)
{
if(ubSlaveNbDataToTransmit > 0)
{
LL_I2C_TransmitData8(I2C1, (uint8_t)(*pSlaveTransmitBuffer++));
ubSlaveNbDataToTransmit--;
}if (ubSlaveNbDataToTransmit > 0) { ... }
else
{
LL_I2C_TransmitData8(I2C1, 0x00);
}else { ... }
}{ ... }
/* ... */
void Slave_Reception_Callback(void)
{
/* ... */
aSlaveReceiveBuffer[ubSlaveReceiveIndex++] = LL_I2C_ReceiveData8(I2C1);
if(Buffercmp8((uint8_t*)aSlaveReceiveBuffer, (uint8_t*)(aCommandCode[0][0]), (ubSlaveReceiveIndex-1)) == 0)
{
ubSlaveInfoIndex = SLAVE_CHIP_NAME;
ubSlaveNbDataToTransmit = strlen(aSlaveInfo[ubSlaveInfoIndex]);
pSlaveTransmitBuffer = (uint8_t*)(aSlaveInfo[ubSlaveInfoIndex]);
}if (Buffercmp8((uint8_t*)aSlaveReceiveBuffer, (uint8_t*)(aCommandCode[0][0]), (ubSlaveReceiveIndex-1)) == 0) { ... }
else if(Buffercmp8((uint8_t*)aSlaveReceiveBuffer, (uint8_t*)(aCommandCode[1][0]), (ubSlaveReceiveIndex-1)) == 0)
{
ubSlaveInfoIndex = SLAVE_CHIP_REVISION;
ubSlaveNbDataToTransmit = strlen(aSlaveInfo[ubSlaveInfoIndex]);
pSlaveTransmitBuffer = (uint8_t*)(aSlaveInfo[ubSlaveInfoIndex]);
}else if (Buffercmp8((uint8_t*)aSlaveReceiveBuffer, (uint8_t*)(aCommandCode[1][0]), (ubSlaveReceiveIndex-1)) == 0) { ... }
}{ ... }
/* ... */
void Slave_Complete_Callback(void)
{
ubSlaveReceiveIndex = 0;
ubSlaveReceiveComplete = 0;
FlushBuffer8(aSlaveReceiveBuffer);
}{ ... }
/* ... */
void Transfer_Complete_Callback()
{
ubMasterTransferComplete = 1;
}{ ... }
/* ... */
void Transfer_Error_Callback()
{
NVIC_DisableIRQ(DMA1_Stream5_IRQn);
LED_Blinking(LED_BLINK_ERROR);
}{ ... }
/* ... */
void Error_Callback(void)
{
NVIC_DisableIRQ(I2C1_EV_IRQn);
NVIC_DisableIRQ(I2C1_ER_IRQn);
LED_Blinking(LED_BLINK_ERROR);
}{ ... }
#ifdef USE_FULL_ASSERT
/* ... */
void assert_failed(uint8_t *file, uint32_t line)
{
/* ... */
while (1)
{
}while (1) { ... }
}assert_failed (uint8_t *file, uint32_t line) { ... }
/* ... */#endif
/* ... */
/* ... */