コード例 #1
0
ファイル: spi.c プロジェクト: larosas/imu_autopilot
void spi_adns9500_read_reg_transmit(spi_package* package) {
	/*copy address into fifo*/
	SSPDR = (*package).data[0];

	/*set bit mode (8bit or 16bit)*/
	SSPCR0 = (*package).bit_mode |  SSP_FRF | SSP_CPOL_ADNS | SSP_CPHA_ADNS | SSP_SCR;
	/*select the device*/
	(*package).slave_select();
	/*enable spi and send fifo*/
	SpiEnable();
	/*wait until the address has been sent(Transmit fifo is emtpy)*/
	while(SSPSR&(1<<BSY));
	/*disable spi*/
	SpiDisable();
	/*wait for T_SRAD and let the sensor prepare data*/
	delay_us(120);
	/*generate clock for ADNS9500 -> MCU transmission*/
	SSPDR = (*package).data[1];
	/*enable spi and send fifo*/
	SpiEnable();
	/*wait until all data has been sent(Transmit fifo is emtpy)*/
	while(SSPSR&(1<<BSY));
	/*disable spi*/
	SpiDisable();
	/*unselect device*/
	(*package).slave_unselect();
	/*read out the dummy bytes or the data bytes*/
	(*package).spi_interrupt_handler();
}
コード例 #2
0
ファイル: nokia1202.c プロジェクト: SmallRoomLabs/BEEPoo
//
// Send a byte to the display, either as a command or data depending on the "cd" flag
//
void LcdSend(uint8_t cd, uint8_t data) {
  LCD_CE_LOW;                                   // Enable LCD ~CE
  if (cd==0) LCD_DI_LOW; else LCD_DI_HIGH;      // Command/Data-bit
  TOGGLECLK;
  SpiEnable(1);
  SpiSend(data);
  SpiDisable();
  LCD_CE_HIGH;                                  // Disable LCD ~CE
}
コード例 #3
0
ファイル: baro_scp.c プロジェクト: CodeMining/paparazzi
/* write 0x0A to 0x03 */
static void baro_scp_start_high_res_measurement(void)
{
  uint8_t cmd  = 0x03 << 2 | 0x02;
  uint8_t data = 0x0A;
  ScpSelect();
  SSPDR = cmd;
  SSPDR = data;
  SpiEnableRti();
  SpiEnable();
}
コード例 #4
0
ファイル: spi.c プロジェクト: 976717326/imu_autopilot
static inline void spi_transmit_single_package(spi_package* package){
	spi_current_package = package;
	/*copy data into fifo*/
	for(int i=0; i<(*spi_current_package).length; i++){
		SSPDR = (*spi_current_package).data[i];
	}
	/*set bit mode (8bit or 16bit)*/
	SSPCR0 = (*spi_current_package).bit_mode |  SSP_FRF | SSP_CPOL | SSP_CPHA | SSP_SCR;
	/*select the device*/
	(*spi_current_package).slave_select();

	/* enable SPI and send package data*/
	SpiClearRti();
	SpiEnableRti();
	SpiEnable();
}
コード例 #5
0
ファイル: baro_scp.c プロジェクト: CodeMining/paparazzi
/* read 0x21 (TEMP), 0x1F (MSB) and 0x20 (LSB) */
static void baro_scp_read(void)
{
  uint8_t cmd0 = 0x21 << 2;
  uint8_t cmd1 = 0x1F << 2;
  uint8_t cmd2 = 0x20 << 2;
  ScpSelect();
  SSPDR = cmd0;
  SSPDR = 0;
  SSPDR = 0;
  SSPDR = cmd1;
  SSPDR = 0;
  SSPDR = cmd2;
  SSPDR = 0;
  SSPDR = 0;
  SpiEnable();
}
コード例 #6
0
ファイル: spi.c プロジェクト: 976717326/imu_autopilot
void spi_transmit(spi_package* package) {
	/*copy data into fifo*/
	for(int i=0; i<(*package).length; i++){
		SSPDR = (*package).data[i];
	}
	/*set bit mode (8bit or 16bit)*/
	SSPCR0 = (*package).bit_mode |  SSP_FRF | SSP_CPOL | SSP_CPHA | SSP_SCR;
	/*select the device*/
	(*package).slave_select();
	/*enable spi and send fifo*/
	SpiEnable();
	/*wait until all data has been sent(Transmit fifo is emtpy)*/
	while(SSPSR&(1<<BSY));
	/*unselect device*/
	(*package).slave_unselect();
	/*disable spi*/
	SpiDisable();
	/*read out the dummy bytes or the data bytes*/
	(*package).spi_interrupt_handler();
}
コード例 #7
0
ファイル: cc1101.cpp プロジェクト: Kreyl/nute
void cc1101_t::Init() {
    // ==== GPIO ====
    PinSetupOut(GPIOA, CC_CS,   omPushPull);
    PinSetupAlterFuncOutput(GPIOA, CC_SCK,  omPushPull);
    PinSetupAlterFuncOutput(GPIOA, CC_MISO, omPushPull);
    PinSetupAlterFuncOutput(GPIOA, CC_MOSI, omPushPull);
    PinSetupIn(GPIOA, CC_GDO0, pudNone);
    PinSetupIn(GPIOA, CC_GDO2, pudNone);
    CsHi();

    // ==== SPI ====    MSB first, master, ClkLowIdle, FirstEdge, Baudrate=f/2
    SpiSetup(CC_SPI, boMSB, cpolIdleLow, cphaFirstEdge, sbFdiv2);
    SpiEnable(CC_SPI);

    // ==== Init CC ====
    CReset();
    FlushRxFIFO();
    RfConfig();
    chEvtInit(&IEvtSrcRx);
    chEvtInit(&IEvtSrcTx);
    State = ccIdle;

    // ==== IRQ ====
    RCC->APB2ENR |= RCC_APB2ENR_AFIOEN; // Enable AFIO clock
    uint8_t tmp = CC_GDO0 / 4;          // Indx of EXTICR register
    uint8_t Shift = (CC_GDO0 & 0x03) * 4;
    AFIO->EXTICR[tmp] &= ~((uint32_t)0b1111 << Shift);    // Clear bits and leave clear to select GPIOA
    tmp = 1<<CC_GDO0;   // IRQ mask
    // Configure EXTI line
    EXTI->IMR  |=  tmp;      // Interrupt mode enabled
    EXTI->EMR  &= ~tmp;      // Event mode disabled
    EXTI->RTSR &= ~tmp;      // Rising trigger disabled
    EXTI->FTSR |=  tmp;      // Falling trigger enabled
    EXTI->PR    =  tmp;      // Clean irq flag
    nvicEnableVector(EXTI4_IRQn, CORTEX_PRIORITY_MASK(IRQ_PRIO_MEDIUM));
}
コード例 #8
0
void micromag_read( void ) {
  MmSelect();
  SpiEnable();
  //  micromag_cur_axe = 0;
  MmTriggerRead();
}