Exemplo n.º 1
0
Arquivo: si446x.c Projeto: flyoo/stm8l
/*===========================================================================
SI446X_W_TX_FIFO();
Function : write data to TX fifo
INTPUT   : txbuffer, a buffer stores TX array
           size,  how many bytes should be written
============================================================================*/
void SI446X_W_TX_FIFO(INT8U *txbuffer, INT8U size)
{
    SI_CSN_LOW();
    SPI_ExchangeByte(WRITE_TX_FIFO);
    while (size--)      { SPI_ExchangeByte(*txbuffer++); }
    SI_CSN_HIGH();
}
Exemplo n.º 2
0
/*
 ================================================================================
 Function : CC1101ReadStatus( )
 Read a status register
 INPUT    : addr, The address of the register
 OUTPUT   : the value read from the status register
 ================================================================================
 */
u8 CC1101ReadStatus(u8 addr) {
	u8 i;
	CC_CSN_LOW();
	SPI_ExchangeByte(addr | READ_BURST);
	i = SPI_ExchangeByte(0xFF);
	CC_CSN_HIGH();
	return i;
}
Exemplo n.º 3
0
/*
 ================================================================================
 Function : GS_CC1101ReadReg( )
 read a byte from the specified register
 INPUT    : addr, The address of the register
 OUTPUT   : the byte read from the rigister
 ================================================================================
 */
u8 GS_CC1101ReadReg(u8 addr) {
	u8 i;
	CC_CSN_LOW();
	SPI_ExchangeByte(addr | READ_SINGLE);
	i = SPI_ExchangeByte(0xFF);
	CC_CSN_HIGH();
	return i;
}
Exemplo n.º 4
0
/*
 ================================================================================
 Function : CC1101WriteMultiReg( )
 Write some bytes to the specified register
 INPUT    : addr, The address of the register
 buff, a buffer stores the values
 size, How many byte should be written
 OUTPUT   : None
 ================================================================================
 */
void CC1101WriteMultiReg(u8 addr, u8 *buff, u8 size) {
	u8 i;
	CC_CSN_LOW();
	SPI_ExchangeByte(addr | WRITE_BURST);
	for (i = 0; i < size; i++) {
		SPI_ExchangeByte(*(buff + i));
	}
	CC_CSN_HIGH();
}
Exemplo n.º 5
0
Arquivo: si446x.c Projeto: flyoo/stm8l
/*===========================================================================
SI446X_READ_RESPONSE();
Function : read a array of command response
INTPUT   : buffer,  a buffer, stores the data responsed
           size,    How many bytes should be read
============================================================================*/
void SI446X_READ_RESPONSE(INT8U *buffer, INT8U size)
{
    SI446X_WAIT_CTS();
    SI_CSN_LOW();
    
	SPI_ExchangeByte(READ_CMD_BUFF);
	while (size--)  { *buffer++ = SPI_ExchangeByte(0xFF); }
    
    SI_CSN_HIGH();
}
Exemplo n.º 6
0
/*
 ================================================================================
 Function : GS_CC1101ReadMultiReg( )
 Read some bytes from the rigisters continously
 INPUT    : addr, The address of the register
 buff, The buffer stores the data
 size, How many bytes should be read
 OUTPUT   : None
 ================================================================================
 */
void GS_CC1101ReadMultiReg(u8 addr, u8 *buff, u8 size) {
	u8 i, j;
	CC_CSN_LOW();
	SPI_ExchangeByte(addr | READ_BURST);
	for (i = 0; i < size; i++) {
		for (j = 0; j < 20; j++)
			;
		*(buff + i) = SPI_ExchangeByte(0xFF);
	}
	CC_CSN_HIGH();
}
Exemplo n.º 7
0
Arquivo: si446x.c Projeto: flyoo/stm8l
/*===========================================================================
SI446X_WAIT_CTS();
Function : wait the device ready to response a command
============================================================================*/
void SI446X_WAIT_CTS(void)
{
    INT8U cts;
    IWDG_ReloadCounter();
    do
    {
        SI_CSN_LOW();
        SPI_ExchangeByte(READ_CMD_BUFF);
        cts = SPI_ExchangeByte(0xFF);
        SI_CSN_HIGH();
    }while(cts != 0xFF);
    IWDG_ReloadCounter();
}
Exemplo n.º 8
0
Arquivo: si446x.c Projeto: flyoo/stm8l
/*===========================================================================
SI446X_NOP();
Function : NO Operation command
============================================================================*/
INT8U SI446X_NOP(void)
{
    INT8U cts;
    SI_CSN_LOW();
    cts = SPI_ExchangeByte(NOP);
    SI_CSN_HIGH();
	return cts;
}
Exemplo n.º 9
0
/*
=================================================================================
LCD_WrDat( );
Function : Write a byte to OLED module
INTPUT   : dt, the data byte
OUTPUT   : None
=================================================================================
*/
void LCD_WrDat(INT8U dt)
{
    unsigned char i;
    OLED_CSN_L( );
    OLED_CMD_H( );//LCD_DC=1;
    SPI_ExchangeByte( dt );
    OLED_CSN_H( );
}
Exemplo n.º 10
0
/*
=================================================================================
LCD_WrCmd( );
Function : Write a command to OLED module
INTPUT   : cmd, the command byte
OUTPUT   : None
=================================================================================
*/
void LCD_WrCmd(INT8U cmd)
{
    unsigned char i;
    OLED_CSN_L( );
    OLED_CMD_L( );//LCD_DC=0;
    SPI_ExchangeByte( cmd );
    OLED_CSN_H( );
}
Exemplo n.º 11
0
Arquivo: si446x.c Projeto: flyoo/stm8l
/*===========================================================================
SI446X_CMD();
Function : Send a command to the device
INTPUT   : cmd, the buffer stores the command array
           cmdsize, the size of the command array
============================================================================*/
void SI446X_CMD(INT8U *cmd, INT8U cmdsize)
{
    SI446X_WAIT_CTS();
    SI_CSN_LOW();
    
    while (cmdsize--)   { SPI_ExchangeByte(*cmd++); }
    
    SI_CSN_HIGH();
}
Exemplo n.º 12
0
Arquivo: si446x.c Projeto: flyoo/stm8l
/*===========================================================================
SI446X_READ_PACKET();
Function : read RX fifo
INTPUT   : buffer, a buffer to store data read
OUTPUT   : received bytes
============================================================================*/
INT8U SI446X_READ_PACKET(INT8U *buffer)
{
    INT8U length, i;
    SI446X_WAIT_CTS();
    SI_CSN_LOW();

    SPI_ExchangeByte(READ_RX_FIFO);
#if PACKET_LENGTH == 0
    length = SPI_ExchangeByte(0xFF);
#else
    length = PACKET_LENGTH;
#endif
    i = length;

    while (length--)    { *buffer++ = SPI_ExchangeByte(0xFF); }
    SI_CSN_HIGH();
    return i;
}
Exemplo n.º 13
0
Arquivo: si446x.c Projeto: flyoo/stm8l
/*===========================================================================
SI446X_SEND_PACKET();
Function : send a packet
INTPUT   : txbuffer, a buffer stores TX array
           size,  how many bytes should be written
           channel, tx channel
           condition, tx condition
============================================================================*/
void SI446X_SEND_PACKET(INT8U *txbuffer, INT8U size, INT8U channel, INT8U condition)
{
    INT8U tx_len = size;

    SI446X_TX_FIFO_RESET();
	SI446X_RX_FIFO_RESET();

    SI446X_CHANGE_STATE(2);
    while(SI446X_GET_DEVICE_STATE() != 2);

	SI446X_WAIT_CTS();
    SI_CSN_LOW();
    SPI_ExchangeByte(WRITE_TX_FIFO);
#if PACKET_LENGTH == 0
    tx_len ++;
    SPI_ExchangeByte(size);
#endif
    while(size --)    { SPI_ExchangeByte(*txbuffer++); }
    SI_CSN_HIGH();

	SI446X_START_TX(channel, condition, tx_len);
}
Exemplo n.º 14
0
/*
 ================================================================================
 Function : CC1101WriteCmd( )
 Write a command byte to the device
 INPUT    : command, the byte you want to write
 OUTPUT   : None
 ================================================================================
 */
void CC1101WriteCmd(u8 command) {
	CC_CSN_LOW();
	SPI_ExchangeByte(command);
	CC_CSN_HIGH();
}
Exemplo n.º 15
0
/*
 ================================================================================
 Function : CC1101WriteReg( )
 Write a byte to the specified register
 INPUT    : addr, The address of the register
 value, the byte you want to write
 OUTPUT   : None
 ================================================================================
 */
void CC1101WriteReg(u8 addr, u8 value) {
	CC_CSN_LOW();
	SPI_ExchangeByte(addr);
	SPI_ExchangeByte(value);
	CC_CSN_HIGH();
}