Bar Logo 3.8/7.6 kw Totem pole Demonstration Application (Part-No. (not specified))
 
Content
     
Loading...
Searching...
No Matches
spi1.c
Go to the documentation of this file.
1
18/*
19© [2023] Microchip Technology Inc. and its subsidiaries.
20
21 Subject to your compliance with these terms, you may use Microchip
22 software and any derivatives exclusively with Microchip products.
23 You are responsible for complying with 3rd party license terms
24 applicable to your use of 3rd party software (including open source
25 software) that may accompany Microchip software. SOFTWARE IS ?AS IS.?
26 NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS
27 SOFTWARE, INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT,
28 MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT
29 WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
30 INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY
31 KIND WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF
32 MICROCHIP HAS BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE
33 FORESEEABLE. TO THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP?S
34 TOTAL LIABILITY ON ALL CLAIMS RELATED TO THE SOFTWARE WILL NOT
35 EXCEED AMOUNT OF FEES, IF ANY, YOU PAID DIRECTLY TO MICROCHIP FOR
36 THIS SOFTWARE.
37*/
38
39// Section: Included Files
40#include <xc.h>
41#include "../spi1.h"
42
43// Section: File specific data type definitions
44
49#define SPI1_DUMMY_DATA 0x0
50
51//Defines an object for SPI_CLIENT_INTERFACE.
52
55 .Deinitialize = &SPI1_Deinitialize,
56 .Close = &SPI1_Close,
57 .Open = &SPI1_Open,
58 .ByteExchange = &SPI1_ByteExchange,
59 .ByteRead = &SPI1_ByteRead,
60 .ByteWrite = &SPI1_ByteWrite,
61 .IsRxReady = &SPI1_IsRxReady,
62 .IsTxReady = &SPI1_IsTxReady,
63};
64
65
72{
73 uint16_t controlRegister1; //SPI1CON1L
74};
75
76static const struct SPI1_CLIENT_CONFIG config[] = {
77 {
78 /*Configuration setting for CLIENT_CONFIG.
79 SPI Mode : Mode 3*/
80 0xc1,//SPI1CON1L
81 },
82 };
83
84// Section: Driver Interface Function Definitions
85
86void SPI1_Initialize (void)
87{
88 //TODO: replace below
89// // SPIBRGL 0;
90// SPI1BRGL = 0x0;
91// // AUDEN disabled; FRMEN disabled; AUDMOD I2S; FRMSYPW One clock wide; AUDMONO stereo; FRMCNT 0x0; MSSEN disabled; FRMPOL disabled; IGNROV disabled; SPISGNEXT not sign-extended; FRMSYNC disabled; URDTEN disabled; IGNTUR disabled;
92// SPI1CON1H = 0x0;
93// // WLENGTH 0;
94// SPI1CON2L = 0x0;
95// // SPIROV disabled; FRMERR disabled;
96// SPI1STATL = 0x0;
97// // SPIURDTL 0;
98// SPI1URDTL = 0x0;
99// // SPIURDTH 0;
100// SPI1URDTH = 0x0;
101// // SPIEN disabled; DISSDO disabled; MCLKEN FOSC/2; CKP Idle:Low, Active:High; SSEN enabled; MSTEN Client; MODE16 disabled; SMP Middle; DISSCK disabled; SPIFE Frame Sync pulse precedes; CKE Idle to Active; MODE32 disabled; SPISIDL disabled; ENHBUF enabled; DISSDI disabled;
102// SPI1CON1L = 0x81;
103 //TODO: replace above
104
105//TODO: remove below
106 SPI1CON1H = 0x00;
107 // WLENGTH 0;
108 SPI1CON2L = 0x00;
109 // SPIROV disabled; FRMERR disabled;
110 SPI1STATL = 0x00;
111 // SPI1BRGL 0;
112 SPI1BRGL = 0x00;
113 // SPITBFEN disabled; SPITUREN disabled; FRMERREN disabled; SRMTEN disabled; SPIRBEN disabled; BUSYEN disabled; SPITBEN disabled; SPIROVEN disabled; SPIRBFEN enabled;
114 SPI1IMSKL = 0x01;
115 // RXMSK 4; TXWIEN disabled; TXMSK 0; RXWIEN disabled;
116 SPI1IMSKH = 0x400;
117 // SPI1URDTL 0;
118 SPI1URDTL = 0x00;
119 // SPI1URDTH 0;
120 SPI1URDTH = 0x00;
121 // SPIEN disabled; DISSDO disabled; MCLKEN FOSC/2; CKP Idle:High, Active:Low; SSEN disabled; MSTEN Slave; MODE16 enabled; SMP Middle; DISSCK disabled; SPIFE Frame Sync pulse precedes; CKE Idle to Active; MODE32 disabled; SPISIDL disabled; ENHBUF disabled; DISSDI disabled;
122 SPI1CON1L = 0x440;
123//TODO: remove above
124}
125
127{
128 SPI1_Close();
129
130 SPI1BRGL = 0x0;
131 SPI1CON1L = 0x0;
132 SPI1CON1H = 0x0;
133 SPI1CON2L = 0x0;
134 SPI1STATL = 0x28;
135 SPI1URDTL = 0x0;
136 SPI1URDTH = 0x0;
137}
138
139void SPI1_Close(void)
140{
141 SPI1CON1Lbits.SPIEN = 0U;
142}
143
144bool SPI1_Open(uint8_t spiConfigIndex)
145{
146 bool status = false;
147 if(!SPI1CON1Lbits.SPIEN)
148 {
149 SPI1CON1L = config[spiConfigIndex].controlRegister1;
150 SPI1CON1Lbits.SPIEN = 1U;
151
152 status = true;
153 }
154 return status;
155}
156
157uint8_t SPI1_ByteExchange(uint8_t byteData)
158{
159 while(1U == SPI1STATLbits.SPITBF)
160 {
161
162 }
163
164 SPI1BUFL = byteData;
165
166 while (1U == SPI1STATLbits.SPIRBE)
167 {
168
169 }
170
171 return SPI1BUFL;
172}
173
174void SPI1_ByteWrite(uint8_t byteData)
175{
176 while(1U == SPI1STATLbits.SPITBF)
177 {
178
179 }
180
181 SPI1BUFL = byteData;
182}
183
184uint8_t SPI1_ByteRead(void)
185{
186 while (1U == SPI1STATLbits.SPIRBE)
187 {
188
189 }
190
191 return SPI1BUFL;
192}
193
195{
196 return (!SPI1STATLbits.SPIRBE);
197}
198
200{
201 return (!SPI1STATLbits.SPITBF);
202}
203
This is the generated driver header file for the SPI1 driver.
static const struct SPI1_CLIENT_CONFIG config[]
Definition spi1.c:76
size_t status
Definition uart1.c:99
void SPI1_Initialize(void)
Initializes SPI1 module, using the given initialization data. This function must be called before any...
Definition spi1.c:86
void SPI1_Deinitialize(void)
Deinitializes the SPI1 to POR values.
Definition spi1.c:126
bool SPI1_Open(uint8_t spiConfigIndex)
Configures SPI1 module with user defined unique configuration.
Definition spi1.c:144
const struct SPI_CLIENT_INTERFACE SPI1_Client
Structure object of type SPI_CLIENT_INTERFACE assigned with name displayed in the Melody Driver User ...
Definition spi1.c:53
bool SPI1_IsRxReady(void)
Returns a boolean value if data is available to read.
Definition spi1.c:194
uint8_t SPI1_ByteRead(void)
Reads one byte of data from SPI1.
Definition spi1.c:184
bool SPI1_IsTxReady(void)
Returns a boolean value if data can be written.
Definition spi1.c:199
void SPI1_Close(void)
Disables the SPI1 module.
Definition spi1.c:139
void SPI1_ByteWrite(uint8_t byteData)
Writes one byte of data.
Definition spi1.c:174
uint8_t SPI1_ByteExchange(uint8_t byteData)
Exchanges one byte of data. This is a blocking function.
Definition spi1.c:157
Structure containing the function pointers of SPI CLIENT driver.
void(* Initialize)(void)
Pointer to SPIx_Initialize e.g. SPI1_Initialize.
uint16_t controlRegister1
Definition spi1.c:73