Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * main.cpp
- *
- * Created on: 4 oct. 2017
- * Author: Duc Nguyen
- */
- #include <stdint.h>
- #include <stdbool.h>
- #include "inc/hw_types.h"
- #include "driverlib/sysctl.h"
- #include "driverlib/ssi.h"
- #include "driverlib/gpio.h"
- #include "driverlib/uart.h"
- #include "inc/hw_memmap.h"
- #include "inc/hw_types.h"
- #include "driverlib/pin_map.h"
- #include "cc1101_register_map.h"
- #include "utils/uartstdio.h"
- void WriteReg(uint32_t addr, uint32_t value);
- int main()
- {
- SysCtlClockSet( SYSCTL_SYSDIV_2 | SYSCTL_USE_OSC | SYSCTL_XTAL_4MHZ | SYSCTL_OSC_MAIN); // set clock 4MHz
- SysCtlPeripheralEnable(SYSCTL_PERIPH_SSI0); // enable modul SSI0;
- SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); // enable port A
- GPIOPinTypeSSI(GPIO_PORTA_BASE, GPIO_PIN_2 | GPIO_PIN_3 | GPIO_PIN_4 | GPIO_PIN_5); // config those pin as SSIO
- SSIDisable(SSI0_BASE); // disable before configuration
- GPIOPinConfigure(GPIO_PA2_SSI0CLK);
- GPIOPinConfigure(GPIO_PA3_SSI0FSS);//configure those pin as SSI function
- GPIOPinConfigure(GPIO_PA4_SSI0RX);// like changing them into alternate function
- GPIOPinConfigure(GPIO_PA5_SSI0TX);
- SSIConfigSetExpClk(SSI0_BASE, SysCtlClockGet(), SSI_FRF_MOTO_MODE_0, SSI_MODE_MASTER, 1000000, 8);
- // config clock and mode (CPHA & CPOL) and bit rate and the bandwidth
- SSIEnable(SSI0_BASE);// enable the module
- //Up here, finish the setup for SSI module...
- //start configuring UART for debug purpose
- SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
- GPIOPinConfigure(GPIO_PA0_U0RX);
- GPIOPinConfigure(GPIO_PA1_U0TX);
- GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
- UARTClockSourceSet(UART0_BASE, UART_CLOCK_PIOSC);
- UARTStdioConfig(0, 115200, SysCtlClockGet());
- // UARTConfigSetExpClk(UART0_BASE, SysCtlClockGet(), 115200, UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE );
- //finish configure UART to the computer
- UARTCharPut(UART0_BASE,'a');
- UARTCharPut(UART0_BASE,'H');
- //now print one line as an example
- //config the CC1101 here
- //
- // Rf settings for CC1101
- //
- WriteReg(IOCFG0,0x06); //GDO0 Output Pin Configuration
- WriteReg(FIFOTHR,0x47); //RX FIFO and TX FIFO Thresholds
- WriteReg(PKTCTRL0,0x05);//Packet Automation Control
- WriteReg(CHANNR,0x01); //Channel Number
- WriteReg(FSCTRL1,0x06); //Frequency Synthesizer Control
- WriteReg(FREQ2,0x10); //Frequency Control Word, High Byte
- WriteReg(FREQ1,0xA7); //Frequency Control Word, Middle Byte
- WriteReg(FREQ0,0x62); //Frequency Control Word, Low Byte
- WriteReg(MDMCFG4,0xFC); //Modem Configuration
- WriteReg(MDMCFG2,0x13); //Modem Configuration
- WriteReg(DEVIATN,0x15); //Modem Deviation Setting
- WriteReg(MCSM0,0x18); //Main Radio Control State Machine Configuration
- WriteReg(FOCCFG,0x16); //Frequency Offset Compensation Configuration
- WriteReg(WORCTRL,0xFB); //Wake On Radio Control
- WriteReg(FSCAL3,0xEA); //Frequency Synthesizer Calibration
- WriteReg(FSCAL2,0x2A); //Frequency Synthesizer Calibration
- WriteReg(FSCAL1,0x00); //Frequency Synthesizer Calibration
- WriteReg(FSCAL0,0x1F); //Frequency Synthesizer Calibration
- WriteReg(TEST2,0x81); //Various Test Settings
- WriteReg(TEST1,0x35); //Various Test Settings
- WriteReg(TEST0,0x09); //Various Test Settings
- // end config
- while(1)
- {
- ;
- }
- }
- //this function
- // write value to address in the spi device, to configue par example
- void WriteReg(uint32_t addr, uint32_t value)
- {
- uint8_t header_adr = (0x00 | addr); // set up the header
- uint32_t dummy = 0x00;
- GPIOPinWrite(GPIO_PORTA_BASE, GPIO_PIN_3, 0x00);// pull csn low
- // wait until MISO pin goes low
- while ( GPIOPinRead(GPIO_PORTA_BASE, GPIO_PIN_4 ));
- //for debugging, enable UART
- UARTprintf("Write addr: 0x%x, header: 0x%x\r\n", addr, header_adr);
- while ( SSIBusy(SSI0_BASE)); //wait until ssi is free
- SSIDataPut(SSI0_BASE, header_adr);
- SSIDataGet(SSI0_BASE, &dummy);
- UARTprintf("Readback status 0x%x\r\n",dummy & 0x00FF);
- //wait until miso pin goes low
- while (GPIOPinRead(GPIO_PORTA_BASE, GPIO_PIN_4));
- //when not busy, write back value to the register
- UARTprintf("write val: 0x%x\r\n",value);
- while( SSIBusy(SSI0_BASE));
- SSIDataPut(SSI0_BASE, value); //get into the register, ready for transfer
- SSIDataGet(SSI0_BASE, &dummy); // read dummy value;
- UARTprintf("read back 2nd status 0x%x\r\n", dummy & 0x00FF);
- GPIOPinWrite(GPIO_PORTA_BASE, GPIO_PIN_3, 0x01); // PULL CSn high, stop writting;
- }
- void
- readReg(uint8_t raddr)
- {
- uint8_t header_read = (0x80 | raddr); //Set up header for reading
- uint32_t dummy = 0x00;
- //Pull the CSn low
- GPIOPinWrite(GPIO_PORTA_BASE,GPIO_PIN_3,0x00);
- //Wait until the MISO pin goes low
- while (GPIOPinRead(GPIO_PORTA_BASE, GPIO_PIN_4));
- //When not busy, write header for reading data from MISO Pin
- UARTprintf("write address for read back: 0x%x\r\n",header_read);
- while(SSIBusy(SSI0_BASE)){} //Wait for SSI to not be busy
- SSIDataPut(SSI0_BASE, header_read); //write header for reading data
- SSIDataGet(SSI0_BASE, &dummy); //read status byte
- UARTprintf("Status 0x%x ", dummy & 0x00FF);
- //Wait until the MISO pin goes low
- while (GPIOPinRead(GPIO_PORTA_BASE, GPIO_PIN_4));
- //When not busy, read data from MISO pin
- while(SSIBusy(SSI0_BASE)){} //wait for SSI to be ready
- SSIDataPut(SSI0_BASE, 0); //Write dummy value
- SSIDataGet(SSI0_BASE, &dummy); //read dummy value
- UARTprintf(" \t\t read back value 0x%x\r\n", dummy & 0x00FF);
- //Pull CSN high
- GPIOPinWrite(GPIO_PORTA_BASE,GPIO_PIN_3,0x1);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement