1 | void gp22_wr_config_reg (void *bus_type, uint8_t opcode_address,
|
2 | uint32_t config_reg_data)
|
3 | {
|
4 | uint8_t Data_Byte_Lo = config_reg_data;
|
5 | uint8_t Data_Byte_Mid1 = config_reg_data>>8;
|
6 | uint8_t Data_Byte_Mid2 = config_reg_data>>16;
|
7 | uint8_t Data_Byte_Hi = config_reg_data>>24;
|
8 |
|
9 | uint8_t common_delay = 0; // important delay (16) at SPI freq.=750kHz
|
10 |
|
11 | // Deactivating Reset SPIx
|
12 | if (bus_type==SPI1) GPIO_WriteBit(GPIOA, GPIO_Pin_4, Bit_RESET);
|
13 | if (bus_type==SPI2) GPIO_WriteBit(GPIOB, GPIO_Pin_12, Bit_RESET);
|
14 |
|
15 | while (SPI_I2S_GetFlagStatus(bus_type, SPI_I2S_FLAG_TXE)==0) {}
|
16 |
|
17 | SPI_I2S_SendData(bus_type, opcode_address); // RAM WR OPCODE+ADDRESS
|
18 | Simple_delay_750ns((void*)common_delay);
|
19 |
|
20 | while (SPI_I2S_GetFlagStatus(bus_type, SPI_I2S_FLAG_TXE)==0) {}
|
21 | SPI_I2S_SendData(bus_type, Data_Byte_Hi); // DATA BYTE HIGH
|
22 | Simple_delay_750ns((void*)common_delay);
|
23 |
|
24 | while (SPI_I2S_GetFlagStatus(bus_type, SPI_I2S_FLAG_TXE)==0) {}
|
25 | SPI_I2S_SendData(bus_type, Data_Byte_Mid2); // DATA MID - 2
|
26 | Simple_delay_750ns((void*)common_delay);
|
27 |
|
28 | while (SPI_I2S_GetFlagStatus(bus_type, SPI_I2S_FLAG_TXE)==0) {}
|
29 | SPI_I2S_SendData(bus_type, Data_Byte_Mid1); // DATA MID - 1
|
30 | Simple_delay_750ns((void*)common_delay);
|
31 |
|
32 | while (SPI_I2S_GetFlagStatus(bus_type, SPI_I2S_FLAG_TXE)==0) {}
|
33 | SPI_I2S_SendData(bus_type, Data_Byte_Lo); // DATA LOW
|
34 | Simple_delay_750ns((void*)common_delay);
|
35 |
|
36 | while (SPI_I2S_GetFlagStatus(bus_type, SPI_I2S_FLAG_TXE)==0) {}
|
37 | Simple_delay_750ns((void*)common_delay);
|
38 |
|
39 | // Reset to device SPIx
|
40 | if (bus_type==SPI1) GPIO_WriteBit(GPIOA, GPIO_Pin_4, Bit_SET);
|
41 | if (bus_type==SPI2) GPIO_WriteBit(GPIOB, GPIO_Pin_12, Bit_SET);
|
42 | }
|