spi.h File Reference

Go to the source code of this file.

Macros

#define SPI_H
 

Enumerations

enum  SPI_GPIO_GroupTypeDef { SPI_GPIO_GROUP_A2A3A4D6 =0, SPI_GPIO_GROUP_B6B7D2D7 }
 Define pin for SPI interface SDO SDI SCK CN A2 A3 A4 D6 B7 B6 D7 D2. More...
 
enum  SPI_ModeTypeDef { SPI_MODE0 = 0, SPI_MODE2, SPI_MODE1, SPI_MODE3 }
 Define the mode for SPI interface. More...
 
enum  SPI_24M_ClkTypeDef {
  SPI_CLK_200K = 0x3c, SPI_CLK_250K = 0x2e, SPI_CLK_500K = 0x17, SPI_CLK_1M = 0x0b,
  SPI_CLK_2M = 0x05, SPI_CLK_4M = 0x02
}
 Define the clk for SPI interface(system clock = 24M) More...
 

Functions

static void reset_spi_moudle (void)
 This function reset SPI module. More...
 
void spi_master_gpio_set (SPI_GPIO_GroupTypeDef PinGrp)
 This function selects a pin port for the SPI interface (master mode) More...
 
void spi_slave_gpio_set (SPI_GPIO_GroupTypeDef PinGrp)
 This function selects a pin port for the SPI interface (slave mode) More...
 
void spi_masterCSpin_select (GPIO_PinTypeDef CSPin)
 This function selects a GPIO pin as CS of SPI function. More...
 
void spi_master_init (unsigned char DivClock, SPI_ModeTypeDef Mode)
 This function configures the clock and working mode for SPI interface. More...
 
void spi_slave_init (unsigned char DivClock, SPI_ModeTypeDef Mode)
 This function configures the clock and working mode for SPI interface. More...
 
void spi_write (unsigned char *Cmd, int CmdLen, unsigned char *Data, int DataLen, GPIO_PinTypeDef CSPin)
 This function serves to write a bulk of data to the SPI slave device specified by the CS pin. More...
 
void spi_read (unsigned char *Cmd, int CmdLen, unsigned char *Data, int DataLen, GPIO_PinTypeDef CSPin)
 This function serves to read a bulk of data from the SPI slave device specified by the CS pin. More...
 
void spi_set_share_mode_en (void)
 This function use to set the share mode of SPI. More...
 

Macro Definition Documentation

◆ SPI_H

#define SPI_H

Enumeration Type Documentation

◆ SPI_GPIO_GroupTypeDef

Define pin for SPI interface SDO SDI SCK CN A2 A3 A4 D6 B7 B6 D7 D2.

Enumerator
SPI_GPIO_GROUP_A2A3A4D6 
SPI_GPIO_GROUP_B6B7D2D7 

◆ SPI_ModeTypeDef

Define the mode for SPI interface.

Enumerator
SPI_MODE0 
SPI_MODE2 
SPI_MODE1 
SPI_MODE3 

◆ SPI_24M_ClkTypeDef

Define the clk for SPI interface(system clock = 24M)

Enumerator
SPI_CLK_200K 
SPI_CLK_250K 
SPI_CLK_500K 
SPI_CLK_1M 
SPI_CLK_2M 
SPI_CLK_4M 

Function Documentation

◆ reset_spi_moudle()

static void reset_spi_moudle ( void  )
inlinestatic

This function reset SPI module.

Parameters
[in]none
Returns
none

◆ spi_master_gpio_set()

void spi_master_gpio_set ( SPI_GPIO_GroupTypeDef  PinGrp)

This function selects a pin port for the SPI interface (master mode)

Parameters
[in]PinGrp- the selected pin port
Returns
none A3:5b7[0] set 1 as spi input,set 0 not as spi input ;5b7[4] set 1 as i2c input ,set 0 not as i2c input A4:5b7[1] set 1 as spi input,set 0 not as spi input ;5b7[5] set 1 as i2c input ,set 0 not as i3c input B6:5b7[2] set 1 as spi input,set 0 not as spi input ;5b7[6] set 1 as i2c input ,set 0 not as i4c input D7:5b7[3] set 1 as spi input,set 0 not as spi input ;5b7[7] set 1 as i2c input ,set 0 not as i5c input 5b6[7:4] set spi or i2c output,5b6[5:4] PA spi sel, 5b6[6] PB spi sel,5b6[7] PD spi_sel spi i2c mux sel: step1:close gpio func; step2:set 0x5a8-0x5af sel spii2c func; step3:set 5b6[7:4] to sel spi or i2c output; step4:set 5b7[7:0] to sel spi or i2c input; step5 if use pd[6]as spi slave csn,need to open pd[2] gpio func,because pd[2]have high priority than pd[6]

◆ spi_slave_gpio_set()

void spi_slave_gpio_set ( SPI_GPIO_GroupTypeDef  PinGrp)

This function selects a pin port for the SPI interface (slave mode)

Parameters
[in]PinGrp- the selected pin port
Returns
none A3:5b7[0] set 1 as spi input,set 0 not as spi input ;5b7[4] set 1 as i2c input ,set 0 not as i2c input A4:5b7[1] set 1 as spi input,set 0 not as spi input ;5b7[5] set 1 as i2c input ,set 0 not as i3c input B6:5b7[2] set 1 as spi input,set 0 not as spi input ;5b7[6] set 1 as i2c input ,set 0 not as i4c input D7:5b7[3] set 1 as spi input,set 0 not as spi input ;5b7[7] set 1 as i2c input ,set 0 not as i5c input 5b6[7:4] set spi or i2c output,5b6[5:4] PA spi sel, 5b6[6] PB spi sel,5b6[7] PD spi_sel spi i2c mux sel: step1:close gpio func; step2:set 0x5a8-0x5af sel spii2c func; step3:set 5b6[7:4] to sel spi or i2c output; step4:set 5b7[7:0] to sel spi or i2c input; step5 if use pd[6]as spi slave csn,need to open pd[2] gpio func,because pd[2]have high priority than pd[6]

◆ spi_masterCSpin_select()

void spi_masterCSpin_select ( GPIO_PinTypeDef  CSPin)

This function selects a GPIO pin as CS of SPI function.

Parameters
[in]CSPin- the selected CS pin
Returns
none

◆ spi_master_init()

void spi_master_init ( unsigned char  DivClock,
SPI_ModeTypeDef  Mode 
)

This function configures the clock and working mode for SPI interface.

Parameters
[in]DivClock- the division factor for SPI module SPI clock = System clock / ((DivClock+1)*2)
[in]Mode- the selected working mode of SPI module Telink spi supports four standard working modes register 0x0b set working mode bit0:CPOL-Clock Polarity ; bit1:CPHA-Clock Phase MODE0: CPOL = 0 , CPHA =0; MODE1: CPOL = 0 , CPHA =1; MODE2: CPOL = 1 , CPHA =0; MODE3: CPOL = 1 , CPHA =1;
Returns
none

◆ spi_slave_init()

void spi_slave_init ( unsigned char  DivClock,
SPI_ModeTypeDef  Mode 
)

This function configures the clock and working mode for SPI interface.

Parameters
[in]DivClock- the division factor for SPI module SPI clock = System clock / ((DivClock+1)*2)
[in]Mode- the selected working mode of SPI module (slave mode)
Returns
none

◆ spi_write()

void spi_write ( unsigned char *  Cmd,
int  CmdLen,
unsigned char *  Data,
int  DataLen,
GPIO_PinTypeDef  CSPin 
)

This function serves to write a bulk of data to the SPI slave device specified by the CS pin.

Parameters
[in]Cmd- pointer to the command bytes needed written into the slave device first before the writing operation of actual data
[in]CmdLen- length in byte of the command bytes
[in]Data- pointer to the data need to write
[in]DataLen- length in byte of the data need to write
[in]CSPin- the CS pin specifing the slave device
Returns
none

◆ spi_read()

void spi_read ( unsigned char *  Cmd,
int  CmdLen,
unsigned char *  Data,
int  DataLen,
GPIO_PinTypeDef  CSPin 
)

This function serves to read a bulk of data from the SPI slave device specified by the CS pin.

Parameters
[in]Cmd- pointer to the command bytes needed written into the slave device first before the reading operation of actual data
[in]CmdLen- length in byte of the command bytes
[out]Data- pointer to the buffer that will cache the reading out data
[in]DataLen- length in byte of the data need to read
[in]CSPin- the CS pin specifing the slave device
Returns
none

◆ spi_set_share_mode_en()

void spi_set_share_mode_en ( void  )

This function use to set the share mode of SPI.

Parameters
[in]none
Returns
none