/********************************************************************** *********** Write TI_Command ***************** *********************************************************************** Aim : command strobe acces NOTE :[ R/W bit (0)] + [ Burst bit (0)] + [6 bit addres] No data is expected. Chip_status_Byte is returned from chip **********************************************************************/ void TI_Command( char command ) { SpiStart(); //Start SPI by CSn Low wait_CHIP_RDYn; //Wait for TI's christal to be stabilized SPI_Send(command); //Send chip command SpiStop(); //Stop SPI by CSn High }
/********************************************************************** *********** TI_Write ************************* *********************************************************************** Aim : write 1 byte data to chip via SPI NOTE :[ R/W bit (0)] + [ Burst bit (0)] + [6 bit addres] + 8 bit data **********************************************************************/ void TI_WriteByte( char addr, char data) { //int dly; SpiStart(); //Start SPI by CSn Low wait_CHIP_RDYn; //Wait for TI's christal to be stabilized SPI_Send(addr); // Send 1 byte addr and write command SPI_Send(data); // Send 1 byte data SpiStop(); //Stop SPI by CSn High }
char TI_Command_Read(char command) { char ret; SpiStart(); //Start SPI by CSn Low wait_CHIP_RDYn; //Wait for TI's christal to be stabilized SPI_Send(command|READ_SINGLE); //Send chip command with READ bit ret=SPI_Send(0x00); //send dummy byte so read status byte SpiStop(); //Stop SPI by CSn High return ret; }
/********************************************************************** *********** TI_Read ************************* *********************************************************************** Aim : Read 1 byte data from chip via SPI NOTE :[ R/W bit (1)] + [ Burst bit (0)] + [6 bit addres] **********************************************************************/ char TI_ReadByte(char addr) { char data = 0; SpiStart(); //Start SPI by CSn Low wait_CHIP_RDYn; //Wait for TI's christal to be stabilized SPI_Send( READ_SINGLE | addr); // R/w bit (1) + Burst bit (0)+ 6 bit addres data = SPI_Send(0x00); // Data read (read 1byte data) via dummy write SpiStop(); //Stop SPI by CSn High return data; }
/********************************************************************** *********** TI_Init ************************* *********************************************************************** Aim : wait for initialization of CC1120 NOTE : **********************************************************************/ void TI_Init(void) { TI_HW_Reset(); SpiStart(); //Start SPI by CSn Low wait_CHIP_RDYn; //Wait for TI's christal to be stabilized // while((SPI_Send(0x00) & 0x80) != 0); // x= SPI_Send(0x00); // Delay(0x5000); SpiStop(); //Stop SPI by CSn High }
/********************************************************************** *********** TI_READ_brst ********************* *********************************************************************** Aim : burst read to TI chip NOTE :[ R/W bit (1)] + [ Burst bit (1)] + [6 bit addres] **********************************************************************/ int TI_Read_brst(int addr, char* buf,int len) { int i = 0; SpiStart(); //Start SPI by CSn Low wait_CHIP_RDYn; //Wait for TI's christal to be stabilized SPI_Send ( READ_BURST | addr ); // Address byte 1 for(i = 0; i < len; i++) // Write data in loop { buf[i] = SPI_Send(0x00); //write data to buffer with size of "len" } SpiStop(); //Stop SPI by CSn High return len; }
/********************************************************************** *********** TI_Write_brst ******************* *********************************************************************** Aim : burst write to TI chip NOTE :[ R/W bit (0)] + [ Burst bit (1)] + [6 bit addres stars with 0x2F00] **********************************************************************/ int TI_Write_brst(int addr,char* buf,int len) { int i = 0; SpiStart(); //Start SPI by CSn Low wait_CHIP_RDYn; //Wait for TI's christal to be stabilized SPI_Send ( WRITE_BURST | addr ); // Send the adrr for(i = 0; i < len; i++) // Burst Write the data { SPI_Send (buf[i]); } SpiStop(); //Stop SPI by CSn High return len; }
void ADXL362_PolledInit(void) { SpiInitPolledMode(ACCEL_ADXL362); // Software Reset ADXL362_WriteReg(ADXL362_SOFT_RESET, ADXL362_RESET_CMD); DelayMs(10); ADXL362_WriteReg(ADXL362_SOFT_RESET, 0x00); // Enable Measurement ADXL362_WriteReg(ADXL362_POWER_CTL, (2 << ADXL362_MEASURE)); s_adxl362_state = ADXL362_WaitForCommand; SpiStop(BARO_MS5611); }