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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
#include "spi.h"
#include <stdio.h>
#include "ch573/gpio.h"
#include "ch573/spi.h"
#define SPI CH573_SPI__SPI_T_INTF
#define SPI0 ch573_spi__spi0
#define GPIO_PORT_A ch573_gpio__gpio_port_a
#define GPIO_PORT_B ch573_gpio__gpio_port_b
#define GPIO_PORT CH573_GPIO__GPIO_PORT_T_INTF
#define GPIO_I CH573_GPIO__GPIO_T_INTF
#define GPIO ch573_gpio__gpio
void enable_spi(void)
{
GPIO_I.pin_alternate.pin_spi0.set(GPIO, OFF);
GPIO_PORT.out.set(GPIO_PORT_A, ON, 12);
GPIO_PORT.dir.set(GPIO_PORT_A, DIR_OUT, 12);
GPIO_PORT.dir.set(GPIO_PORT_A, DIR_OUT, 14);
GPIO_PORT.pd_drv.set(GPIO_PORT_A, 0, 12);
GPIO_PORT.pd_drv.set(GPIO_PORT_A, 0, 14);
GPIO_PORT.dir.set(GPIO_PORT_B, DIR_OUT, 12);
GPIO_PORT.dir.set(GPIO_PORT_B, DIR_OUT, 14);
GPIO_PORT.pd_drv.set(GPIO_PORT_B, 0, 12);
GPIO_PORT.pd_drv.set(GPIO_PORT_B, 0, 14);
GPIO_PORT.out.set(GPIO_PORT_B, OFF, 14);
GPIO_PORT.out.set(GPIO_PORT_B, ON, 12);
GPIO_PORT.dir.set(GPIO_PORT_B, DIR_IN, 13);
GPIO_PORT.dir.set(GPIO_PORT_B, DIR_IN, 15);
GPIO_PORT.dir.set(GPIO_PORT_A, DIR_IN, 13);
GPIO_PORT.dir.set(GPIO_PORT_A, DIR_IN, 15);
SPI.clock_div.set(SPI0, 16);
SPI.ctrl_mod.all_clear.set(SPI0, 1);
// SPI.ctrl_mod.set(SPI0, 0xe0); // Set mosi and sck
SPI.ctrl_mod.all_clear.set(SPI0, 0);
SPI.ctrl_mod.pin_enable.set(SPI0, 0x7); // Set mosi and sck
SPI.ctrl_cfg.auto_if.set(SPI0, 1);
SPI.ctrl_cfg.dma_enable.set(SPI0, OFF);
}
void run_spi(void)
{
GPIO_PORT.out.set(GPIO_PORT_A, ON, 12);
while (1) {
GPIO_PORT_A->clr |= 1 << 12;
SPI.ctrl_mod.fifo_dir.set(SPI0, FIFO_DIR_OUTPUT);
// R8_SPI0_CTRL_MOD &= ~RB_SPI_FIFO_DIR;
SPI.data_buf.set(SPI0, 0xaa);
// R8_SPI0_BUFFER = 0xaa;
while (!SPI.int_flag.free.get(SPI0));
GPIO_PORT.out.set(GPIO_PORT_A, ON, 12);
}
}
|