-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmaster-write-read-polling.c
46 lines (38 loc) · 1.09 KB
/
master-write-read-polling.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/** Custom libs **/
#include "Spi.h"
int main(int argc, char** argv)
{
/* Master device SPI settings */
SpiStandardConfig_t spiMasterConfig = {
.pinSelect = {
.sdiPin = SDI2_RPB13,
.sdoPin = SDO2_RPB2,
.ss1Pin = GPIO_RPB10
},
.isMasterEnabled = true,
.frameWidth = SPI_WIDTH_8BIT,
.clkMode = SPI_CLK_MODE_0,
.sckFreq = 10000000
};
/* SPI module base address set */
SpiSfr_t *spiMasterSfr = &SPI2_MODULE;
/* Configure SPI module */
SPI_ConfigStandardModeSfr(spiMasterSfr, spiMasterConfig);
/* Test data variables */
uint8_t masterRxData[24] = {0};
uint8_t masterTxData[24] = {0xAB, 0x00, 0xCC, 0x00,
0xFF, 0xAB, 0x12, 0x21,
0xA0, 0x12, 0x00, 0xF1,
0xAB, 0x00, 0xCC, 0x00,
0xFF, 0xAB, 0x12, 0x21,
0xA0, 0x12, 0x00, 0xF1};
/* Configure which Slave will be addressed */
SPI_EnableSsState(spiMasterConfig.pinSelect.ss1Pin);
/* Polling-based SPI read and write */
SPI_MasterReadWrite(spiMasterSfr, masterRxData, masterTxData, 24);
while(1)
{
/* Main program execution */
}
return 0;
}