Example #1
0
File: lcd.c Project: maxk9/etro_new
//-------------------------------------------------------------------------------------------------
// Write data to current position
//-------------------------------------------------------------------------------------------------
void GLCD_WriteData(unsigned char dataToWrite)
{
    while(GLCD_ReadStatus(screen_x / 64)&DISPLAY_STATUS_BUSY);
       
//    GPIO_StructInit(&GPIO_InitStructure);
//    GPIO_InitStructure.GPIO_Pin = (0xFF );
//    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
//    GPIO_Init(KS0108_PORT, &GPIO_InitStructure);
    
    GPIO_Init(KS0108_PORT,GPIO_PIN_ALL,GPIO_MODE_OUT_PP_LOW_FAST);

    GPIO_WriteLow(GPIOC, KS0108_RW);
    GLCD_Delay();
    GPIO_WriteHigh(GPIOC, KS0108_RS);
    GLCD_Delay();

	GPIO_Write(KS0108_PORT, (GPIO_Pin_TypeDef)(dataToWrite ));
    GLCD_Delay();
	
    GLCD_EnableController(screen_x / 64);
    GLCD_Delay();
    GPIO_WriteHigh(GPIOC, KS0108_EN);
    GLCD_Delay();
    GPIO_WriteLow(GPIOC, KS0108_EN);
    GLCD_Delay();
    GLCD_DisableController(screen_x / 64);
    screen_x++;
}
Example #2
0
uint8_t SPISendByte(uint8_t Data)
{

#ifdef USE_SPI_MODULE
  /*!< Wait until the transmit buffer is empty */
  while (SPI_GetFlagStatus(SPI_FLAG_TXE) == RESET)
  {}

  /*!< Send the byte */
  SPI_SendData(Data);

  /*!< Wait to receive a byte*/
  while (SPI_GetFlagStatus(SPI_FLAG_RXNE) == RESET)
  {}

  /*!< Return the byte read from the SPI bus */
  return SPI_ReceiveData();
#else
  uint8_t i;
  for(i=0;i<8;i++)
  {
	GPIO_WriteLow(ENC_SCK_PORT,ENC_SCK_PIN);
        if(Data & 0x80)
          GPIO_WriteHigh(ENC_MOSI_PORT,ENC_MOSI_PIN);
        else
          GPIO_WriteLow(ENC_MOSI_PORT,ENC_MOSI_PIN);
	GPIO_WriteHigh(ENC_SCK_PORT,ENC_SCK_PIN);
	Data <<=1;
  }
  GPIO_WriteLow(ENC_SCK_PORT,ENC_SCK_PIN);
  
  return 0;
#endif
  
}
Example #3
0
//SpeedSet:
//SPI_BAUDRATEPRESCALER_2    
//SPI_BAUDRATEPRESCALER_4   
//SPI_BAUDRATEPRESCALER_8    
//SPI_BAUDRATEPRESCALER_16 
static void spi_init(SPI_BaudRatePrescaler_TypeDef SPI_BaudRatePrescaler)
{
  GPIO_Init(LCD_CS_PIN,GPIO_MODE_OUT_PP_HIGH_FAST);
  GPIO_Init(LCD_CD_PIN,GPIO_MODE_OUT_PP_HIGH_FAST);
  GPIO_Init(LCD_RST_PIN,GPIO_MODE_OUT_PP_HIGH_FAST);  
  GPIO_Init(LCD_LIGHT_PIN,GPIO_MODE_OUT_PP_HIGH_FAST);
  
  GPIO_Init(SPI_SCK_PIN,GPIO_MODE_OUT_PP_LOW_FAST);  
  GPIO_Init(SPI_MOSI_PIN,GPIO_MODE_OUT_PP_HIGH_FAST);  
  GPIO_Init(SPI_MISO_PIN,GPIO_MODE_IN_PU_NO_IT);
  
  //打开flash电源 开发板独有
  GPIO_Init(GPIOE,GPIO_PIN_0,GPIO_MODE_OUT_PP_HIGH_FAST);
  GPIO_WriteHigh(GPIOE,GPIO_PIN_0);
  
  //打开背光
  GPIO_WriteLow(LCD_LIGHT_PIN);
  
  GPIO_WriteLow(LCD_RST_PIN);
  u8g_10MicroDelay();
  GPIO_WriteHigh(LCD_RST_PIN);
  //关闭FLASH CS
  GPIO_WriteLow(GPIOG,GPIO_PIN_0);
  
  //初始化SPI
  SPI_DeInit(); 
  SPI_Init(SPI_FIRSTBIT_MSB, SPI_BaudRatePrescaler, SPI_MODE_MASTER, SPI_CLOCKPOLARITY_LOW, SPI_CLOCKPHASE_1EDGE, SPI_DATADIRECTION_2LINES_FULLDUPLEX, SPI_NSS_SOFT, 0x00);
  SPI_Cmd(ENABLE);
}
Example #4
0
File: lcd.c Project: maxk9/etro_new
//-------------------------------------------------------------------------------------------------
// Enalbe Controller (0-2)
//-------------------------------------------------------------------------------------------------
void GLCD_EnableController(unsigned char controller)
{
switch(controller){
	case 0 : GPIO_WriteLow(GPIOC, KS0108_CS1); break;
	case 1 : GPIO_WriteLow(GPIOC, KS0108_CS2); break;
	//case 2 : PORT_ResetBits(KS0108_PORT, KS0108_CS3); break;
	default: break;
	}
}
Example #5
0
void LCD_NYB(unsigned char nyb, char type){
	unsigned char temp;
	temp = (nyb<<4) & 0xF0;
	GPIO_Write(LCD_PORT,temp);
   
	if(type == 0){
		GPIO_WriteLow(LCD_PORT,LCD_RS); //COMMAND MODE
	} else {
	GPIO_WriteHigh(LCD_PORT,LCD_RS); //CHARACTER/DATA MODE
	}
   
	GPIO_WriteHigh(LCD_PORT,LCD_E); //ENABLE LCD DATA LINE
	DelayMS(1); //SMALL DELAY
	GPIO_WriteLow(LCD_PORT,LCD_E); //DISABLE LCD DATA LINE
}
Example #6
0
void 	run_led(u8 sta)
{
	if(sta==1)
		GPIO_WriteLow(GPIOA,GPIO_PIN_3);
	else
		GPIO_WriteHigh(GPIOA,GPIO_PIN_3);
}
Example #7
0
int main( void ){

    uint16_t i;
    // Reset GPIO port D to a default state
    GPIO_DeInit(GPIOD);

    /* Clock configuration -----------------------------------------*/
    //CLK_Config();

    /*AWU configuration --------------------------------------------*/
    AWU_Config();

    GPIO_Init(GPIOD, GPIO_PIN_0, GPIO_MODE_OUT_PP_LOW_FAST);
    // The main loop
    while( 1 ){

        GPIO_WriteLow(GPIOD, GPIO_PIN_0);

        for(i=0;i<10000;i++) // A delay loop
        {
            nop();
        }
        GPIO_WriteHigh(GPIOD, GPIO_PIN_0);

        halt();/* Program halted */
    }

}
Example #8
0
/**
  * @brief Example firmware main entry point.
  * @par Parameters:
  * None
  * @retval 
  * None
  */
void main(void)
{

  u8 Leds; /* Contains which LEDs to operate */

  /* Initialize I/Os in Output Mode */
  GPIO_Init(LEDS_PORT, (LED1_PIN | LED2_PIN | LED3_PIN | LED4_PIN), GPIO_MODE_OUT_PP_LOW_FAST);

  /* Toggles LEDs */

  while (1)
  {
    /* Check button status */
    if ((GPIO_ReadInputData(BUTTON_PORT) & BUTTON_PIN) == (u8)0x00)
    {
      /* Button is pressed */
      Leds = (LED2_PIN | LED3_PIN);
    }
    else
    {
      /* Button is released */
      Leds = (LED1_PIN | LED4_PIN);
    }
    /* LEDs ON */
    GPIO_WriteHigh(LEDS_PORT, Leds);
    Delay((u16)60000);
    Delay((u16)60000);
    /* LEDs OFF */
    GPIO_WriteLow(LEDS_PORT, Leds);
    Delay((u16)60000);
    Delay((u16)60000);
  }

}
Example #9
0
//*********************************//
void  sysio_ini(void)
{
    GPIO_DeInit(GPIOD);
    GPIO_Init(GPIOD,GPIO_PIN_2 ,GPIO_MODE_IN_PU_NO_IT); //data165
    GPIO_Init(GPIOD,GPIO_PIN_3 ,GPIO_MODE_OUT_PP_HIGH_FAST); //clk165
    GPIO_Init(GPIOD,GPIO_PIN_4 ,GPIO_MODE_OUT_PP_HIGH_FAST); //sh165
    GPIO_WriteHigh(GPIOD,H165_SH);
    GPIO_WriteHigh(GPIOD,H165_CLK);

    GPIO_DeInit(GPIOC);
    GPIO_Init(GPIOC,GPIO_PIN_4,GPIO_MODE_OUT_PP_HIGH_FAST);//led
    GPIO_Init(GPIOC,GPIO_PIN_5,GPIO_MODE_OUT_PP_HIGH_FAST);//c138
    GPIO_Init(GPIOC,GPIO_PIN_6,GPIO_MODE_OUT_PP_HIGH_FAST);//b138
    GPIO_Init(GPIOC,GPIO_PIN_7,GPIO_MODE_OUT_PP_HIGH_FAST);//a138
    GPIO_WriteLow(GPIOC,GPIO_PIN_4);

    GPIO_DeInit(GPIOB);
    GPIO_Init(GPIOB,GPIO_PIN_4 ,GPIO_MODE_OUT_OD_HIZ_SLOW); //clk1637
    GPIO_Init(GPIOB,GPIO_PIN_5 ,GPIO_MODE_OUT_OD_HIZ_SLOW); //sh1637
    GPIO_WriteHigh(GPIOB,T1637_CLK);
    GPIO_WriteHigh(GPIOB,T1637_DATA);



}
Example #10
0
static void rd(char h)
{
  if(h)
     GPIO_WriteHigh(LCDDIG_PORT,LCDDIG_RD_PIN);
  else
     GPIO_WriteLow(LCDDIG_PORT,LCDDIG_RD_PIN);
}
Example #11
0
static void cs(char h)
{
  if(h)
     GPIO_WriteHigh(LCDDIG_CS_PORT,LCDDIG_CS_PIN);
  else
     GPIO_WriteLow(LCDDIG_CS_PORT,LCDDIG_CS_PIN);
}
Example #12
0
/**
  ******************************************************************************
  * @brief Adjustable led blinking speed using touch sensing keys
  * KEY1: LED1 is blinking
  * KEY1: LED1 is blinking faster
  * KEY1: LED1 don't blink anymore
  * @par Parameters:
  * None
  * @retval void None
  * @par Required preconditions:
  * None
  ******************************************************************************
  */
void ExtraCode_StateMachine(void)
{
  if ((TSL_GlobalSetting.b.CHANGED) && (TSLState == TSL_IDLE_STATE))
  {
    TSL_GlobalSetting.b.CHANGED = 0;

    if (sSCKeyInfo[0].Setting.b.DETECTED) /* KEY 1 touched */
    {
      BlinkSpeed++;
      BlinkSpeed = BlinkSpeed % 4;  // mike - was 3 
    }
  }
/*
  * Mike added - just worked out the action sequence for the stm8s 'new-code-install' 
  they call it download - my ASD get confused with this and freezes - 
  in the project tab - look for the debug and download words
  - debug tab - select a statement in C code in prog and can 'run to ursor' 
  - can go (F5) 
  next to change the case statement to add extra case and toggle an extra LED to be added 
  
  */
  switch (BlinkSpeed)
  {
    case 0 :
      GPIO_WriteHigh(GPIOD, GPIO_PIN_0);
 //     GPIO_WriteHigh(GPIOD, GPIO_PIN_1);
      GPIO_WriteHigh(GPIOD, GPIO_PIN_2);        // mike added
      break;

    case 1 :
      GPIO_WriteLow(GPIOD, GPIO_PIN_2);
      if (TSL_Tick_Flags.b.User_Flag_100ms == 1)
      {
        Delay(&Toggle, 2*MilliSec);
      }
      break;

    case 2 :
      if (TSL_Tick_Flags.b.User_Flag_100ms == 1)
      {
        Delay(&Toggle, 1*MilliSec);
      }
      break;
      
    case 3 :
      if (TSL_Tick_Flags.b.User_Flag_100ms == 1)
      {
        Delay(&Toggle, 1*MilliSec);
  //      GPIO_WriteHigh(GPIOD, GPIO_PIN_1);
          GPIO_WriteReverse(GPIOD, GPIO_PIN_2); // each time we go here we toggle
      }
      break;

    default :
      if (TSL_Tick_Flags.b.User_Flag_100ms == 1)
      {
        Delay(&Toggle, 1*Sec);
      }
  }
}
Example #13
0
/* 
   功能描述:读取按键状态,  根据不同按键电路和编号方式修改本函数
   入口参数:无
   出口参数:按键编号
	 
	 ROW : PD7 PD6 PD5
	 COLUMN : PG5 PG4 PG3 PG2
   */
static u8 KEY_Read(void)
{    
  u8 KCode = 0;
	u8 row = 0, column = 0;
	u8 t;
	GPIO_WriteLow(KEY_COLUMN_PORT, KEY_COLUMN_PINALL);	 
	t = (~GPIO_ReadInputData(KEY_ROW_PORT))&KEY_ROW_PINALL;
	if(t)
		{
			// 有键按下,找到它
			u8 t2 = ~KEY_COLUMN1_PIN;
			while(++column <= KEY_COLUMN_NUM)
			{
				KEY_COLUMN_PORT->ODR |= KEY_COLUMN_PINALL; 							// 所有列线置高
				KEY_COLUMN_PORT->ODR &= t2;								 							// 扫描列置底
				row = (~GPIO_ReadInputData(KEY_ROW_PORT))&KEY_ROW_PINALL;	// 读行线
				if( row == t)
					break;
				else
					t2 >>= 1;
			}
			KCode = 3*(column-1);
			if( row == KEY_ROW1_PIN ) KCode += 1;
			else if(row == KEY_ROW2_PIN) KCode += 2;
			else KCode += 3;
		}
	return KCode;
}
Example #14
0
static void set_gpio_level(GPIO_TypeDef *PORT, GPIO_Pin_TypeDef Pin, uint8_t level)
{
  if(level != 0){
		GPIO_WriteHigh(PORT, Pin);
	}else{
		GPIO_WriteLow(PORT, Pin);
	}
}
Example #15
0
static void data(char h)
{
  GPIO_Init(LCDDIG_PORT, (GPIO_Pin_TypeDef)(LCDDIG_DATA_PIN ), GPIO_MODE_OUT_PP_LOW_FAST);
  if(h)
     GPIO_WriteHigh(LCDDIG_PORT,LCDDIG_DATA_PIN);
  else
     GPIO_WriteLow(LCDDIG_PORT,LCDDIG_DATA_PIN);
}
void _Device_Set_ADP_SOC(unsigned char enable){
  if(enable){
    //DeviceOn
    GPIO_WriteHigh(ADP_SOC_PORT, ADP_SOC_PIN);
  }else{
    //DeviceOff
    GPIO_WriteLow(ADP_SOC_PORT, ADP_SOC_PIN);
  }
}
Example #17
0
void initLCD(void){
	GPIO_DeInit(LCD_PORT);
	GPIO_Init(LCD_PORT, GPIO_PIN_ALL, GPIO_MODE_OUT_PP_LOW_FAST);

	GPIO_WriteLow(LCD_PORT,LCD_E); //clear enable
	GPIO_WriteLow(LCD_PORT,LCD_RS); //going to write command
   
	DelayMS(30); //delay for LCD to initialise.
	LCD_NYB(0x03,0); //Required for initialisation
	DelayMS(5); //required delay
	LCD_NYB(0x03,0); //Required for initialisation
	DelayMS(1); //required delay
	LCD_DATA(0x02,0); //set to 4 bit interface, 1 line and 5*7 font
	LCD_DATA(0x28,0); //set to 4 bit interface, 2 line and 5*10 font
	LCD_DATA(0x0c,0); //set to 4 bit interface, 2 line and 5*7 font
	LCD_DATA(0x01,0); //clear display
	LCD_DATA(0x06,0); //move cursor right after write
}
Example #18
0
File: lcd.c Project: maxk9/etro_new
void GLCD_Reset(void)
{
    GPIO_WriteHigh(GPIOC, KS0108_RES);
    GLCD_Delay();
    GPIO_WriteLow(GPIOC, KS0108_RES);
    GLCD_Delay();
    GPIO_WriteHigh(GPIOC, KS0108_RES);
    
    while(GLCD_ReadStatus(0)&DISPLAY_STATUS_BUSY);
}
Example #19
0
//RS485 使能配置,flag=0使能接收 flag=1使能发送 port默认为1
void RS485_RSV(u8 port, u8 flag)
{
	if(port == 1)
	{
		if(flag ==0)
			GPIO_WriteLow(GPIOD,GPIO_PIN_4);	
		else
			GPIO_WriteHigh(GPIOD,GPIO_PIN_4);				
			
	}
}
Example #20
0
// Enable or Disable the LCD backlight
void LCD_Backlight(FunctionalState NewState)
{
  if (NewState == DISABLE)
  {
    GPIO_WriteLow(LCD_BACKLIGHT_PORT, LCD_BACKLIGHT_PIN);
  }
  else
  {
    GPIO_WriteHigh(LCD_BACKLIGHT_PORT, LCD_BACKLIGHT_PIN);
  }
}
Example #21
0
// Enable or Disable the LCD through CS pin
void LCD_ChipSelect(FunctionalState NewState)
{
  if (NewState == DISABLE)
  {
    GPIO_WriteLow(LCD_CS_PORT, LCD_CS_PIN); /* CS pin low: LCD disabled */
  }
  else
  {
    GPIO_WriteHigh(LCD_CS_PORT, LCD_CS_PIN); /* CS pin high: LCD enabled */
  }
}
Example #22
0
/*******************************************************************************
* 名    称: BSP_LED_On
* 功    能: 打开LED
* 入口参数: led = ALL_LEDS  打开所有LED
*            led = LED1      打开LED1
*            led = LED2      打开LED2
* 出口参数: 无
* 作  者: Roger-WY
* 创建日期: 2015-05-30
* 修    改:
* 修改日期:
* 备    注:
*******************************************************************************/
void  BSP_LED_On (uint8_t led)
{
    switch (led) {
        case 0:
        GPIO_WriteLow(LED1_GPIO_PORT, LED1_GPIO_PIN);
        GPIO_WriteLow(LED2_GPIO_PORT, LED2_GPIO_PIN);
        break;

        case 1:
        GPIO_WriteLow(LED1_GPIO_PORT, LED1_GPIO_PIN);
        break;

        case 2:
        GPIO_WriteLow(LED2_GPIO_PORT, LED2_GPIO_PIN);
        break;

        default:
        break;
    }
}
Example #23
0
File: lcd.c Project: maxk9/etro_new
//-------------------------------------------------------------------------------------------------
// Read Status byte from specified controller (0-2)
//-------------------------------------------------------------------------------------------------
unsigned char GLCD_ReadStatus(unsigned char controller)
{
    unsigned char status;

//    GPIO_StructInit(&GPIO_InitStructure);
//    GPIO_InitStructure.GPIO_Pin = 0xFF ;
//    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
//    GPIO_Init(KS0108_PORT, &GPIO_InitStructure);
    GPIO_Init(KS0108_PORT,GPIO_PIN_ALL,GPIO_MODE_IN_PU_NO_IT);
    
    GPIO_WriteHigh(GPIOC, KS0108_RW);
    GPIO_WriteLow(GPIOC, KS0108_RS);
    GLCD_EnableController(controller);
    GLCD_Delay();
    GPIO_WriteHigh(GPIOC, KS0108_EN);
    GLCD_Delay();
    status = ((GPIO_ReadInputData(KS0108_PORT) ) & 0xFF);
    GPIO_WriteLow(GPIOC, KS0108_EN);
    GLCD_DisableController(controller);
    return status;
}
Example #24
0
void CAN_Node_OW_init(void)
{
    GPIO_Init(OW_PORT, OW_IN, GPIO_MODE_IN_FL_NO_IT); // external pull up
    GPIO_Init(OW_PORT, OW_OUT, GPIO_MODE_OUT_PP_LOW_FAST);
    GPIO_WriteLow(OW_PORT, OW_OUT);

    // Configure TIM1 to run at 1MHz frequency.
    // NOTE assuming master clock frequency is 8MHz.
    TIM1_DeInit();
    TIM1_TimeBaseInit(7, TIM1_COUNTERMODE_UP, 60, 0);
    TIM1_SelectOnePulseMode(TIM1_OPMODE_SINGLE);
}
Example #25
0
//Method to send strings via UART
void UART_SendStr(const char *s)
{
	//Set Max485 in Transmitter mode
	GPIO_WriteHigh(GPIOA, GPIO_PIN_3);
	while(*s)
	{
	UART2_SendData8((uint8_t)(*s));
	while ((UART2->SR & UART2_SR_TXE ) != UART2_SR_TXE );
	s++;
	}
	//Set Max485 in Receiver mode
	GPIO_WriteLow(GPIOA, GPIO_PIN_3);
}
Example #26
0
File: lcd.c Project: maxk9/etro_new
//-------------------------------------------------------------------------------------------------
// Write command to specified controller
//-------------------------------------------------------------------------------------------------
void GLCD_WriteCommand(unsigned char commandToWrite, unsigned char controller)
{
    while(GLCD_ReadStatus(controller)&DISPLAY_STATUS_BUSY);
//    GPIO_StructInit(&GPIO_InitStructure);
//    GPIO_InitStructure.GPIO_Pin  = (0xFF );
//    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
//    GPIO_Init(KS0108_PORT, &GPIO_InitStructure);

    GPIO_Init(KS0108_PORT,GPIO_PIN_ALL,GPIO_MODE_OUT_PP_LOW_FAST);
    
    GPIO_WriteLow(GPIOC, (GPIO_Pin_TypeDef)(KS0108_RS | KS0108_RW));
    GLCD_Delay();
    GLCD_EnableController(controller);
    GLCD_Delay();
	GPIO_Write(KS0108_PORT, (GPIO_Pin_TypeDef)(commandToWrite ));
    GLCD_Delay();
    GPIO_WriteHigh(GPIOC, KS0108_EN);
    GLCD_Delay();
    GPIO_WriteLow(GPIOC, KS0108_EN);
    GLCD_Delay();
    GLCD_DisableController(controller);
}
Example #27
0
/*******************************************************************************
 * 名    称: Bsp_Pm25Init
 * 功    能: PM2.5传感器硬件初始化
 * 入口参数: 无
 * 出口参数: 无
 * 作  者: Roger-WY
 * 创建日期: 2015-07-20
 * 修    改:
 * 修改日期:
 * 备    注:
 *******************************************************************************/
void Bsp_Pm25Init(void)
{
    /***********************************************
    * 描述: 初始化PM2.5传感器内部LED 端口配置
    */
    GPIO_Init(PM25LEDPORT, (GPIO_Pin_TypeDef)PM25LEDPIN, GPIO_MODE_OUT_PP_LOW_FAST);
    GPIO_WriteLow(PM25LEDPORT, PM25LEDPIN);

    /***********************************************
    * 描述: 初始化采集PM2.5传感器的ADC通道
    */
    Bsp_InitAdc();	    /* 初始化 ADC1 模块 */

}
Example #28
0
//****************读取HC165数据
void  Read165(u8 *rdata)
{
    u8 num=0;
    GPIO_WriteLow(GPIOD,H165_SH);
    asm("nop");
    asm("nop");
    GPIO_WriteHigh(GPIOD,H165_SH);
    asm("nop");
    for(num=0; num<4; num++)
    {
        for(u8 i=0; i<8; i++)
        {
            *(rdata+num)<<=1;
            if(GPIO_ReadInputPin(GPIOD,H165_DATA)) {
                *(rdata+num) += 1;
            }
            GPIO_WriteLow(GPIOD,H165_CLK);
            asm("nop");
            GPIO_WriteHigh(GPIOD,H165_CLK);       //上升沿
            asm("nop");
        }
    }
}
Example #29
0
uint8_t SPIReadByte(void)
{
  uint8_t Data = 0;
#ifdef USE_SPI_MODULE
  

  /*!< Wait until the transmit buffer is empty */
  while (SPI_GetFlagStatus(SPI_FLAG_TXE) == RESET)
  {}
  /*!< Send the byte */
  SPI_SendData(SD_DUMMY_BYTE);

  /*!< Wait until a data is received */
  while (SPI_GetFlagStatus(SPI_FLAG_RXNE) == RESET)
  {}
  /*!< Get the received data */
  Data = SPI_ReceiveData();
#else
  
  uint8_t i;
  GPIO_WriteLow(ENC_SCK_PORT,ENC_SCK_PIN);
  for(i=0;i<8;i++)
  {	
	GPIO_WriteHigh(ENC_SCK_PORT,ENC_SCK_PIN);
	Data <<=1;
        
        if(0 != GPIO_ReadInputPin(ENC_MISO_PORT,ENC_MISO_PIN)) 
          Data |= 0x01;
	GPIO_WriteLow(ENC_SCK_PORT,ENC_SCK_PIN);
  }
  
  
#endif 
  /*!< Return the shifted data */
  return Data;
  
}
Example #30
0
/**
  * @brief How to make  a write followed by a read in the E²PROM.
  * @par Examples description
	* - Write 8 bytes on the devive  (E²PROM) 0xA0.
  * - Read back the 8 bytes written on the devive  (E²PROM) 0xA0.
	* - Check the coherency between the written and read Data.
  * @par Parameters:
  * None
  * @retval 
  * None
  */
void main()
{

    /* Initialize I/Os in Output Mode */
    GPIO_Init(LEDS_PORT, (LED1_PIN | LED2_PIN | LED3_PIN | LED4_PIN), GPIO_MODE_OUT_PP_LOW_FAST);

    /* Optional: put here as example only */
    I2C_DeInit();

    /* Initialize the I2C */
    I2C_EEInit();

    /* All LEDs are ON per default */
    GPIO_WriteLow(LEDS_PORT, (LED1_PIN | LED2_PIN | LED3_PIN | LED4_PIN));

    /*** WRITE SEQUENCE ***/
   I2C_EE_PageWrite(Buffer, Base_Add, Buffer_size);
    Delay(1000); /* To let eeprom the time to finish the write operation */

    /***  READ SEQUENCE ***/
    I2C_EE_BufferRead(Data, Base_Add, Buffer_size);
        
     /*** Check transmitted and received buffers ***/
    for (i =Buffer_size; i > 0; i--)
    {
        if (Buffer[i-1] != Data[i-1])
        {
            /* Toggle only LED1 if error is detected */
            while (1)
            {
                GPIO_WriteReverse(LEDS_PORT, LED1_PIN);
                Delay((u16)60000);
            }
        }
    }

    /* Toggle all LEDs when I2C communication is terminated and buffers are ok */
    while (1)
    {
        GPIO_WriteReverse(LEDS_PORT, (LED2_PIN | LED3_PIN | LED4_PIN));
        Delay((u16)60000);
    }

}