Document content:
1, Engineering related auxiliary functions, such as reset delay function;
2. The SPI Interface program is written, and the Wireless Transceiver module is configured using the SPI interface.
time node:2014/11/4~2014/11/6
First, Engineering Auxiliary function writing
The beginning of a main program, the first thing to do is to reset and initialize the relevant modules, etc., the project initialization operation is as follows:
To initialize the MCU, the Mcu_init is as follows:
In MCU initialization, the SPI interface is initialized, i.e. the off-SPI Nsel is 1. SDN is 0 and is defined as follows:
Cled 0, as a power-on indicator, when the program is running, pull the low p0_7 foot for indication.
After the SDN pull-up, by the above available, to achieve the RF chip reset operation.
After a certain period of time delay, complete the wake of the chip.
Finally, through a certain time delay, send the POWER_UP command to the RF chip, start the normal operation.
Second, SPI Interface Program Authoring
The MCU and the rfic use the SPI interface to connect, the project uses 4-wire method, the corresponding PIN is defined as follows:
Wherein the Nsel is a chip-selectable enable signal, the low level is active, the miso is the serial output from the device, that is, from Rfic to mcu;mosi the serial output of the main device, that is, from the MCU to the rfic.
The SPI program header file looks like this:
The two functions of enable and shutdown SPI are defined in the header file above Spiclear&spiset
It can be realized by enabling Nsel.
There are also four functions senddata_noresp/getresp/byte and spireadwrite.
The previous three functions were applied in different scenarios, with the aforementioned documents we know that each command sent is sent in bytes.
(1) for wts/read_cmd/tx_fifo_cmd, etc. are single byte;
Some of the rest of the CMD is sent in a number of bytes, which is divided into the need to reply and do not need to reply two.
(2) For Get_in_status_cmd need GETRESPONSE,WTS operation is also need to use to GetResponse;
(3) for the rest of the majority of the CMD is sent directly continuous, do not need to reply, that is, Getnoresponse.
(4) The above three functions root to the bottom, are each byte through the SPI interface with the MCU peer, that is, the use of spireadwrite.
1 , Spireadwrite function Writing
A: When the read function is defined first, the variable temp that reads the value is returned, and the Restoreea of the storage interrupt state
B: Turn off the system interrupt before sending the SPI data;
C: Processing of the output 8bit data:
A: Pull low sck, used to generate the rising edge drive data transmission;
B: Judge the data high, 1 is set Mosi 1, and vice versa 0;
C: Pull high sck, generate a clock rising edge drive mosi;
D: Shift the 8bit data one bit to the left, processing the secondary high
E: The following program is read time program, the variable temp left one
F: Determine the data received on the miso pin, 1, will be the temp position 1, and vice versa 0
G: Cycle The above operation until the 8bit data is processed
D: End of data transfer, set SCK to 0 that is the default state
E: Restore System Interrupt Status
F: Returns the value read
2 , Spi_senddatabyte function Writing
The function is simpler, which is to use the 1 function once, as shown below
3 , Spi_senddatagetresp function Writing
The value that the function obtains is the data that the rfic transmits to the MCU via the SPI interface. The procedure is as follows:
The function sends useless data to the SPI interface (0XFF, which is always set Mosi to 1), and then gets the response.
4 , Spi_senddatagetnoresp function Writing
The function transmits data to the MCU data via the SPI interface. The procedure is as follows:
The function sends the specified length of data to the SPI interface, *pbdatain points to the data being sent.
Specific information about how the above functions are used is described in the post-document.
Rfic4463_f3c&d