-
Notifications
You must be signed in to change notification settings - Fork 0
/
L99SM81V_Interface.c
89 lines (77 loc) · 1.82 KB
/
L99SM81V_Interface.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include "L99SM81V_Interface.h"
#include "mcc_generated_files/mcc.h"
#include "timers.h"
#include <string.h>
#include <stdio.h>
#include "shell.h"
void L99SM81V_SpiInit(void)
{
SPI1_Initialize();
SPI1_Open(SPI1_DEFAULT);
}
void L99SM81V_SpiDeinit(void)
{
SPI1_Close();
}
void L99SM81V_EnterShutdown(void)
{
EN_SetLow();
delay_ms(100);
}
void L99SM81V_ExitShutdown(void)
{
EN_SetHigh();
send_chars("EN High\n");
delay_ms(10);
send_chars("after delay EN High\n");
}
GSB_t L99SM81V_SpiWriteRegisters(uint8_t cRegAddress, uint8_t* out_buffer, uint8_t* in_buffer)
{
uint8_t cmd;
GSB_t gsb;
cmd=cRegAddress&0x3F;
CSN_SetLow();
gsb=(GSB_t)SPI1_ExchangeByte(cmd);
in_buffer[0]=SPI1_ExchangeByte(out_buffer[0]);
in_buffer[1]=SPI1_ExchangeByte(out_buffer[1]);
CSN_SetHigh();
return gsb;
}
GSB_t L99SM81V_SpiReadRegisters(uint8_t cRegAddress, uint8_t* in_buffer)
{
uint8_t cmd,b;
GSB_t gsb;
b=0;
cmd=(cRegAddress&0x3F)|0x40;
CSN_SetLow();
gsb=(GSB_t)SPI1_ExchangeByte(cmd);
in_buffer[0]=SPI1_ExchangeByte(b);
in_buffer[1]=SPI1_ExchangeByte(b);
CSN_SetHigh();
return gsb;
}
GSB_t L99SM81V_SpiReadClearRegisters(uint8_t cRegAddress, uint8_t* out_mask, uint8_t* in_buffer)
{
uint8_t cmd;
GSB_t gsb;
cmd=(cRegAddress&0x3F)|0x80;
CSN_SetLow();
gsb=(GSB_t)SPI1_ExchangeByte(cmd);
in_buffer[0]=SPI1_ExchangeByte(out_mask[0]);
in_buffer[1]=SPI1_ExchangeByte(out_mask[1]);
CSN_SetHigh();
return gsb;
}
GSB_t L99SM81V_SpiReadDeviceInformation(uint8_t cRegAddress, uint8_t* in_buffer)
{
uint8_t cmd,b,b1;
GSB_t gsb;
b=0;
cmd=(cRegAddress&0x3F)|0xC0;
CSN_SetLow();
gsb=(GSB_t)SPI1_ExchangeByte(cmd);
in_buffer[0]=SPI1_ExchangeByte(b);
b1=SPI1_ExchangeByte(b);
CSN_SetHigh();
return gsb;
}