Exemplo n.º 1
1
void spi2serial_main(void) {
    uint8_t status;
    /* TODO load listening address from flash. */
    uint8_t thisAddr[5]= {97, 83, 22, 222, 121};

    init_stdio_USART2();
    init_delay();

    SPI2_Init();

    delay_ms(10);

    nrf24l01Init();

    delay_ms(100);
    status = nRF24_Check();

    if (status == 1) {
        for (;;);
    }
    nrfSetRxMode(92, 5, thisAddr);
    init_node_link();

    for (;;) {
        status = SPI2Serial_Loop();
        if (status) {
            nrfSetRxMode(92, 5, thisAddr);
        }
    }
}
Exemplo n.º 2
0
// Main
void main (void)
{
	// Init the system clock
	SystemInitClock();
	
	// Enable the peripherals
	SystemEnablePeripheral(PERIPHERAL_AFIO);
	SystemEnablePeripheral(PERIPHERAL_IOPA);
	SystemEnablePeripheral(PERIPHERAL_IOPB);
	SystemEnablePeripheral(PERIPHERAL_IOPC);
	SystemEnablePeripheral(PERIPHERAL_IOPD);
	SystemEnablePeripheral(PERIPHERAL_IOPE);
	SystemEnablePeripheral(PERIPHERAL_DMA1);

	// Init the FLASH chip and SPI module
	// Init the ENC chip and SPI module
	FLASH_Init();
	SPI1_Init();
	SPI2_Init();
	ENC_Init();

	// Init kernel
	KERNEL_Init();

	// Create tasks
	KERNEL_AddTask(&TaskDescriptor_TaskENC);

	// Start kernel (this function never returns)
	KERNEL_Start();
}
Exemplo n.º 3
0
void NRF24L01_Init(void)
{
	GPIO_InitTypeDef GPIO_InitStructure;

	//RCC configuration
	RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB,ENABLE); //GPIOB CLOCK
	RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC,ENABLE); //GPIOC CLOCK

	//CE
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
	GPIO_InitStructure.GPIO_OType=GPIO_OType_PP;
	GPIO_InitStructure.GPIO_PuPd=GPIO_PuPd_UP;
	GPIO_InitStructure.GPIO_Pin = NRF24L01_CE_Pin;
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
	GPIO_Init(GPIOC, &GPIO_InitStructure);

	//CSN
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
	GPIO_InitStructure.GPIO_OType=GPIO_OType_PP;
	GPIO_InitStructure.GPIO_PuPd=GPIO_PuPd_UP;
	GPIO_InitStructure.GPIO_Pin = NRF24L01_CSN_Pin;
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;	
	GPIO_Init(GPIOC, &GPIO_InitStructure);

	NRF24L01_CE_L; // RF PWR OFF
	NRF24L01_CSN_H; // Chip Select Disabled
	//NRF24L01_ExitInit();
	SPI2_Init();
}
int main(void)
{
	unsigned int nCount;
	unsigned char vEncoder[20]="--------------------";
	int i;
  RCC_Configuration();
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
	NVIC_Configuration();
		EXTI_Configuration();
  USART1_Init();
	USART2_Init();															
	USART3_Init();
	UART4_Init();
	UART5_Init();
	SPI2_Init();
	SysTick_Init();
	//init_NRF24L01();
	RX_Mode();
	//nRF24L01_ISR();
	
  while(1)
{

	//Serial_PutString("While ");


}
}	 
Exemplo n.º 5
0
void node_main(void) {
    uint8_t status;
    /* TODO load listening address from flash. */
    uint8_t thisAddr[5]= {97, 89, 64, 222, 121};

    init_stdio_USART2();
    init_delay();

    SPI2_Init();

    delay_ms(10);

    nrf24l01Init();

    delay_ms(100);
    status = nRF24_Check();

    if (status == 1) {
        for (;;);
    }
    printf("nRF check OK!\n");

    nrfSetRxMode(92, 5, thisAddr);
    init_node_link();
    printf("init_node_link OK!\n");
    nRF_Task_Init();
    /* From now on, controls and sensors can be initialized. */
    init_switches();
    printf("init_switches OK!\n");

    for (;;) {
        nRF_Task_Loop();
        delay_ms(1);
    }
}
Exemplo n.º 6
0
void ADNS9200_SPI_Init(void)
{
  GPIO_InitTypeDef GPIO_InitStructure;
  SPI_InitTypeDef  SPI_InitStructure;
  
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
  
  //NCS inital
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;				
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; 		 
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_Init(GPIOB, &GPIO_InitStructure);	
  GPIO_SetBits(GPIOB,GPIO_Pin_12);				
  
  
  SPI2_Init();   
  
  SPI_Cmd(SPI2,DISABLE);  
  
  SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex; 
  SPI_InitStructure.SPI_Mode = SPI_Mode_Master;		
  SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;		
  SPI_InitStructure.SPI_CPOL = SPI_CPOL_High;		
  SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge;	
  SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;		
  SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_256;		
  SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;	
  SPI_InitStructure.SPI_CRCPolynomial = 7;	
  SPI_Init(SPI2, &SPI_InitStructure); 
  
  SPI_Cmd(SPI2,ENABLE);
  ADNS9200_CS=1;  
  
}
//初始化24L01的IO口
void NRF24L01_Init(void)
{
  	RCC->APB2ENR|=1<<3;     //使能PORTB时钟 	    
 	RCC->APB2ENR|=1<<5;		//使能PORTD时钟
 	RCC->APB2ENR|=1<<8;		//使能PORTG时钟
	//这里pb12和pd2拉高,是为了防止互相影响 .
	//因为他们共用一个SPI口. 	 
	GPIOB->CRH&=0XFFF0FFFF; 
	GPIOB->CRH|=0X00030000;	//PB12 推挽 	    
	GPIOB->ODR|=1<<12;    	//PB12上拉 防止W25X的干扰
				   
	GPIOD->CRL&=0XFFFFF0FF; 
	GPIOD->CRL|=0X00000300;	//PD2 推挽 	    
	GPIOD->ODR|=1<<2;    	//PD2上拉   禁止SD卡的干扰

	GPIOG->CRL&=0X00FFFFFF; 
	GPIOG->CRL|=0X33000000;	//PG6 7 推挽 	    
	GPIOG->CRH&=0XFFFFFFF0; 
	GPIOG->CRH|=0X00000008;	//PG8 输入 	    
	GPIOG->ODR|=7<<6;    	//PG6 7 8 上拉	   

	SPI2_Init();    		//初始化SPI	  
	//针对NRF的特点修改SPI的设置
 	SPI2->CR1&=~(1<<6); 	//SPI设备失能
	SPI2->CR1&=~(1<<1); 	//空闲模式下SCK为0 CPOL=0
	SPI2->CR1&=~(1<<0); 	//数据采样从第1个时间边沿开始,CPHA=0  
	SPI2->CR1|=1<<6; 		//SPI设备使能
	
	NRF24L01_CE=0; 			//使能24L01
	NRF24L01_CSN=1;			//SPI片选取消	 		 	 
}
Exemplo n.º 8
0
void InitRc522(void)
{
  SPI2_Init();
  PcdReset();
  PcdAntennaOff();  
  PcdAntennaOn();
  M500PcdConfigISOType( 'A' );
}
void RC522_Init(void)
{
    RC522_GPIO_Config();        //引脚初始化
    SPI2_Init();      //SPI初始化
    PcdReset();                 //复位模块   
    PcdAntennaOff();            //关闭天线
    PcdAntennaOn();             //打开天线
    M500PcdConfigISOType( 'A' );//设置工作方式
}
Exemplo n.º 10
0
void  NRF24L01_Init(void)
{
	SPI2_Init(); //初始化SPI
	NRF24L01_CE_L();          //使能24L01
	NRF24L01_CSN_H();        //SPI片选取消
	EXTI_Config();//配置中断
	//清除接收、发送缓冲区、标志
	NRF24L01_Write_Reg(NRF24L01_FLUSH_RX,0xff);//清除RX FIFO寄存器
	NRF24L01_Write_Reg(NRF24L01_FLUSH_TX,0xff);//清除TX FIFO寄存器 
	NRF24L01_Write_Reg(NRF24L01_WRITE_REG+NRF24L01_STATUS,0xff); //清除TX_DS或MAX_RT中断标志	
}
Exemplo n.º 11
0
//初始化24L01的IO口
void NRF24L01_Init(void)
{ 	
	GPIO_InitTypeDef GPIO_InitStructure;
  	SPI_InitTypeDef  SPI_InitStructure;

	RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOD|RCC_APB2Periph_GPIOG, ENABLE);	 //使能PB,D,G端口时钟
    	
// 	
// 	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;				 //PB12上拉 防止W25X的干扰
//  	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; 		 //推挽输出
//  	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
//  	GPIO_Init(GPIOB, &GPIO_InitStructure);	//初始化指定IO
//  	GPIO_SetBits(GPIOB,GPIO_Pin_12);//上拉				
 	
// 	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;				 //PD2推挽输出上拉   禁止SD卡的干扰
//  	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; 		 //推挽输出
// 	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
//  	GPIO_SetBits(GPIOD,GPIO_Pin_2);//初始化指定IO

	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6|GPIO_Pin_7;	//PG6 7 推挽
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;	
 	GPIO_Init(GPIOG, &GPIO_InitStructure);//初始化指定IO
  
	GPIO_InitStructure.GPIO_Pin  = GPIO_Pin_8;   
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD; //PG8 输入 
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;	
	GPIO_Init(GPIOG, &GPIO_InitStructure);

// 	GPIO_ResetBits(GPIOG,GPIO_Pin_6|GPIO_Pin_7|GPIO_Pin_8);//PG6,7,8上拉					 
		 
    SPI2_Init();    		//初始化SPI	 
 
	SPI_Cmd(SPI2, DISABLE); // SPI外设不使能

	SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;  //SPI设置为双线双向全双工
	SPI_InitStructure.SPI_Mode = SPI_Mode_Master;		//SPI主机
    SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;		//发送接收8位帧结构
	SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low;		//时钟悬空低
	SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge;	//数据捕获于第1个时钟沿
	SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;		//NSS信号由软件控制
	SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_16;		//定义波特率预分频的值:波特率预分频值为16
	SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;	//数据传输从MSB位开始
	SPI_InitStructure.SPI_CRCPolynomial = 7;	//CRC值计算的多项式
	SPI_Init(SPI2, &SPI_InitStructure);  //根据SPI_InitStruct中指定的参数初始化外设SPIx寄存器
 
	SPI_Cmd(SPI2, ENABLE); //使能SPI外设
			 
	NRF24L01_CE=0; 			//使能24L01
	NRF24L01_CSN=1;			//SPI片选取消  
	 		 	 
}
Exemplo n.º 12
0
void System_Config(void)
{
	LED_GPIO_Config();
	USART2_DT_Config();
	SPI2_Init();
	AT25512_SPI_GPIO_Config();	
	PwmInit();
	Timer5Init();
	Timer3Init();
	Receive_Config();
	SPI4_Config();
	MS5803_Config();
	MPU9250_Config();
	mavlink_int();	
}
Exemplo n.º 13
0
Arquivo: 24l01.c Projeto: 2cats/STM32
//初始化24L01的IO口
void NRF24L01_Init(void)
{ 	
	GPIO_InitTypeDef GPIO_InitStructure;
  SPI_InitTypeDef  SPI_InitStructure;

 	RCC_APB2PeriphClockCmd(NRF24L01_GPIO_RCC, ENABLE);	 //使能PB,D,G端口时钟

//CE&CS
	GPIO_InitStructure.GPIO_Pin = NRF24L01_Pin_CE|NRF24L01_Pin_CSN;	//PG6 7 推挽 	 
	GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;
		GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
 	GPIO_Init(NRF24L01_GPIO, &GPIO_InitStructure);//初始化指定IO
  
//Pin IRQ
	GPIO_InitStructure.GPIO_Pin  = NRF24L01_Pin_IRQ;   
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; //PG8 输入  
	
	GPIO_Init(NRF24L01_GPIO, &GPIO_InitStructure);



  SPI2_Init();    		//初始化SPI	 
 
	SPI_Cmd(SPI2, DISABLE); // SPI外设不使能

	SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;  //SPI设置为双线双向全双工
	SPI_InitStructure.SPI_Mode = SPI_Mode_Master;		//SPI主机
  SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;		//发送接收8位帧结构
	SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low;		//时钟悬空低
	SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge;	//数据捕获于第1个时钟沿
	SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;		//NSS信号由软件控制
	SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_16;		//定义波特率预分频的值:波特率预分频值为16
	SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;	//数据传输从MSB位开始
	SPI_InitStructure.SPI_CRCPolynomial = 7;	//CRC值计算的多项式
	SPI_Init(SPI2, &SPI_InitStructure);  //根据SPI_InitStruct中指定的参数初始化外设SPIx寄存器
 
	SPI_Cmd(SPI2, ENABLE); //使能SPI外设
			 
	NRF24L01_CE_LOW 			//使能24L01
	NRF24L01_CSN_HIGH			//SPI片选取消
	 		 	 
}
Exemplo n.º 14
0
//初始化24L01的IO口
void NRF24L01_IO_Init(void)
{
  	GPIO_InitTypeDef GPIO_InitStructure;		                                              //定义GPIO初始化结构体    
    /* 使能GPIOB,GPIOD,GPIOE的AHB1时钟*/
    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB , ENABLE);
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;											  //设置管脚模式为输出模式
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;										  //设置翻转速度为100Mhz,M4就是快啊
    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;											  //设置输出类型为推挽输出
    GPIO_InitStructure.GPIO_Pin = (GPIO_Pin_0|GPIO_Pin_1);									//设置管脚为Pin_5,根据自己液晶接法设置
	GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;										  //设置上/下拉电阻为无上拉下拉电阻		
    GPIO_Init(GPIOB, &GPIO_InitStructure);

    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;                     
  	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
  	GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;//设置为上拉
  	GPIO_Init(GPIOB, &GPIO_InitStructure);
    GPIO_SetBits(GPIOB,GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2);
    SPI2_Init();
 	SPI2_SetSpeed(SPI_SPEED_8);//
}
Exemplo n.º 15
0
//初始化SPI FLASH的IO口
void SPI_Flash_Init(void)
{
	RCC->APB2ENR|=1<<3;     //使能PORTB时钟 	    
 	RCC->APB2ENR|=1<<5;		//使能PORTD时钟
 	RCC->APB2ENR|=1<<8;		//使能PORTG时钟
	GPIOB->CRH&=0XFFF0FFFF; 
	GPIOB->CRH|=0X00030000;	//PB12 推挽 	    
	GPIOB->ODR|=1<<12;    	//PB12上拉
	//这里pd2和pg7拉高,是为了防止NRF24L01和SD卡影响FLASH的烧写.
	//因为他们共用一个SPI口. 
	GPIOD->CRL&=0XFFFFF0FF; 
	GPIOD->CRL|=0X00000300;	//PD2 推挽 	    
	GPIOD->ODR|=1<<2;    	//PD2上拉

	GPIOG->CRL&=0X0FFFFFFF; 
	GPIOG->CRL|=0X30000000;	//PG7 推挽 	    
	GPIOG->ODR|=1<<7;    	//PG7 上拉
	SPI2_Init();		   	//初始化SPI
	SPI2_SetSpeed(SPI_SPEED_2);//设置为18M时钟,高速模式
	SPI_FLASH_TYPE=SPI_Flash_ReadID();//读取FLASH ID.
}  
Exemplo n.º 16
0
uint8_t LineFollow_Init()
{
	lineFollowState = INIT_STATE;
	lineFollowErrorType = NO_ERR;

	readCycle = 0;

	maximumSensorValue = 0;
	maximumThreshold = 0;
	distanceCorrectionUnit = 0;
	maxAvgDiff = 0;
	edgeValueVerifyingCounter = 0;

	quantizedDistance = 0;
	distanceAddition = 0;
	distanceFromLine = 0;
	previousDistanceFromLine = 0;

	frontAverage = 0;
	rearAverage = 0;

	/* Controller parameters */
	Kp = 3;
	Kd = 0;

	/* Init peripheral drivers */
	TIM4_Config();
	NVIC_TIM4();
	SPI2_Init();
	ADEXT_Init();
	MUX_Init();
	SHIFT_Init();
	SERVO_Init();

	return 0;
}
Exemplo n.º 17
0
/******************************************
*函数名称:SPI_init
*函数功能:spi1, spi2 initial
*入口参数:无	
*出口参数:无		   
*返 回 值:无
*全局变量:无
*调用函数:无
******************************************/
void SPI_init(void)
{
    SPI1_Init();
    SPI2_Init();
}
Exemplo n.º 18
0
void Peripherals_Init(void)
{
#ifdef NVIC_AUTOINIT
  NVIC_Init();
#endif /* NVIC_AUTOINIT */
#ifdef SIM_AUTOINIT
  SIM_Init();
#endif /* SIM_AUTOINIT */

#ifdef MCM_AUTOINIT
  MCM_Init();
#endif /* MCM_AUTOINIT */
#ifdef PMC_AUTOINIT
  PMC_Init();
#endif /* PMC_AUTOINIT */
#ifdef PORTA_AUTOINIT
  PORTA_Init();
#endif /* PORTA_AUTOINIT */
#ifdef PORTB_AUTOINIT
  PORTB_Init();
#endif /* PORTB_AUTOINIT */
#ifdef PORTC_AUTOINIT
  PORTC_Init();
#endif /* PORTC_AUTOINIT */
#ifdef PORTD_AUTOINIT
  PORTD_Init();
#endif /* PORTD_AUTOINIT */
#ifdef PORTE_AUTOINIT
  PORTE_Init();
#endif /* PORTE_AUTOINIT */

#ifdef ADC0_AUTOINIT
  ADC0_Init();
#endif /* ADC0_AUTOINIT */
#ifdef ADC1_AUTOINIT
  ADC1_Init();
#endif /* ADC1_AUTOINIT */
#ifdef AIPS0_AUTOINIT
  AIPS0_Init();
#endif /* AIPS0_AUTOINIT */
#ifdef AIPS1_AUTOINIT
  AIPS1_Init();
#endif /* AIPS1_AUTOINIT */
#ifdef AXBS_AUTOINIT
  AXBS_Init();
#endif /* AXBS_AUTOINIT */
#ifdef CAN0_AUTOINIT
  CAN0_Init();
#endif /* CAN0_AUTOINIT */
#ifdef CMP0_AUTOINIT
  CMP0_Init();
#endif /* CMP0_AUTOINIT */
#ifdef CMP1_AUTOINIT
  CMP1_Init();
#endif /* CMP1_AUTOINIT */
#ifdef CMP2_AUTOINIT
  CMP2_Init();
#endif /* CMP2_AUTOINIT */
#ifdef CMT_AUTOINIT
  CMT_Init();
#endif /* CMT_AUTOINIT */
#ifdef CRC_AUTOINIT
  CRC_Init();
#endif /* CRC_AUTOINIT */
#ifdef DAC0_AUTOINIT
  DAC0_Init();
#endif /* DAC0_AUTOINIT */
#ifdef DMAMUX_AUTOINIT
  DMAMUX_Init();
#endif /* DMAMUX_AUTOINIT */
#ifdef DMA_AUTOINIT
  DMA_Init();
#endif /* DMA_AUTOINIT */
#ifdef ENET_AUTOINIT
  ENET_Init();
#endif /* ENET_AUTOINIT */
#ifdef EWM_AUTOINIT
  EWM_Init();
#endif /* EWM_AUTOINIT */
#ifdef FB_AUTOINIT
  FB_Init();
#endif /* FB_AUTOINIT */
#ifdef FMC_AUTOINIT
  FMC_Init();
#endif /* FMC_AUTOINIT */
#ifdef FTFE_AUTOINIT
  FTFE_Init();
#endif /* FTFE_AUTOINIT */
#ifdef FTM0_AUTOINIT
  FTM0_Init();
#endif /* FTM0_AUTOINIT */
#ifdef FTM1_AUTOINIT
  FTM1_Init();
#endif /* FTM1_AUTOINIT */
#ifdef FTM2_AUTOINIT
  FTM2_Init();
#endif /* FTM2_AUTOINIT */
#ifdef FTM3_AUTOINIT
  FTM3_Init();
#endif /* FTM3_AUTOINIT */
#ifdef I2C0_AUTOINIT
  I2C0_Init();
#endif /* I2C0_AUTOINIT */
#ifdef I2C1_AUTOINIT
  I2C1_Init();
#endif /* I2C1_AUTOINIT */
#ifdef I2C2_AUTOINIT
  I2C2_Init();
#endif /* I2C2_AUTOINIT */
#ifdef I2S0_AUTOINIT
  I2S0_Init();
#endif /* I2S0_AUTOINIT */
#ifdef LLWU_AUTOINIT
  LLWU_Init();
#endif /* LLWU_AUTOINIT */
#ifdef LPTMR0_AUTOINIT
  LPTMR0_Init();
#endif /* LPTMR0_AUTOINIT */
#ifdef MPU_AUTOINIT
  MPU_Init();
#endif /* MPU_AUTOINIT */
#ifdef PDB0_AUTOINIT
  PDB0_Init();
#endif /* PDB0_AUTOINIT */
#ifdef PIT_AUTOINIT
  PIT_Init();
#endif /* PIT_AUTOINIT */
#ifdef PTA_AUTOINIT
  PTA_Init();
#endif /* PTA_AUTOINIT */
#ifdef PTB_AUTOINIT
  PTB_Init();
#endif /* PTB_AUTOINIT */
#ifdef PTC_AUTOINIT
  PTC_Init();
#endif /* PTC_AUTOINIT */
#ifdef PTD_AUTOINIT
  PTD_Init();
#endif /* PTD_AUTOINIT */
#ifdef PTE_AUTOINIT
  PTE_Init();
#endif /* PTE_AUTOINIT */
#ifdef RCM_AUTOINIT
  RCM_Init();
#endif /* RCM_AUTOINIT */
#ifdef RNG_AUTOINIT
  RNG_Init();
#endif /* RNG_AUTOINIT */
#ifdef RTC_AUTOINIT
  RTC_Init();
#endif /* RTC_AUTOINIT */
#ifdef SDHC_AUTOINIT
  SDHC_Init();
#endif /* SDHC_AUTOINIT */
#ifdef SMC_AUTOINIT
  SMC_Init();
#endif /* SMC_AUTOINIT */
#ifdef SPI0_AUTOINIT
  SPI0_Init();
#endif /* SPI0_AUTOINIT */
#ifdef SPI1_AUTOINIT
  SPI1_Init();
#endif /* SPI1_AUTOINIT */
#ifdef SPI2_AUTOINIT
  SPI2_Init();
#endif /* SPI2_AUTOINIT */
#ifdef SystemControl_AUTOINIT
  SystemControl_Init();
#endif /* SystemControl_AUTOINIT */
#ifdef SysTick_AUTOINIT
  SysTick_Init();
#endif /* SysTick_AUTOINIT */
#ifdef UART0_AUTOINIT
  UART0_Init();
#endif /* UART0_AUTOINIT */
#ifdef UART1_AUTOINIT
  UART1_Init();
#endif /* UART1_AUTOINIT */
#ifdef UART2_AUTOINIT
  UART2_Init();
#endif /* UART2_AUTOINIT */
#ifdef UART3_AUTOINIT
  UART3_Init();
#endif /* UART3_AUTOINIT */
#ifdef UART4_AUTOINIT
  UART4_Init();
#endif /* UART4_AUTOINIT */
#ifdef UART5_AUTOINIT
  UART5_Init();
#endif /* UART5_AUTOINIT */
#ifdef USB0_AUTOINIT
  USB0_Init();
#endif /* USB0_AUTOINIT */
#ifdef USBDCD_AUTOINIT
  USBDCD_Init();
#endif /* USBDCD_AUTOINIT */
#ifdef VREF_AUTOINIT
  VREF_Init();
#endif /* VREF_AUTOINIT */
#ifdef WDOG_AUTOINIT
  WDOG_Init();
#endif /* WDOG_AUTOINIT */
}
Exemplo n.º 19
0
int main(void)
{
    AppMode_T AppMode;
    WDTIMK = 0U;	/* enable INTWDTI interrupt */
   
    
    HardwareSetup();
    MSTimerInit();
    
    /************************initializa LCD module********************************/
    SPI2_Init();
    InitialiseLCD();
    led_init();
    
    /* Default app mode */
    AppMode = RUN_EXOSITE;

    /* Determine if SW1 & SW3 is pressed at power up to enter nvm erase mode */
    if (Switch1IsPressed() && Switch3IsPressed())
    {

        DisplayLCD(LCD_LINE1, "*NVM ERASED*");
        DisplayLCD(LCD_LINE2, "Reboot      ");
        DisplayLCD(LCD_LINE3, "  Device    ");
        while(1)
        {
            // wait here
        }
    }
    else if(Switch1IsPressed())
    {
        AppMode = ACTIVATE_MODEM;
    }
    
    DisplayLCD(LCD_LINE1, "Initializing");
    DisplayLCD(LCD_LINE2, "  Novatel   ");
    DisplayLCD(LCD_LINE3, "   Modem    ");
        
    // reset the modem
    P8 &= ~(1<<POWER_OFF_PIN); //SET LOW
    PM8 &= ~(1<<POWER_OFF_PIN); //SET AS OUTPUT
    P8 |= (1<<POWER_OFF_PIN);  //SET HIGH
    MSTimerDelay(500); //pulse
    P8 &= ~(1<<POWER_OFF_PIN); //SET LOW


    // pulse the phone pin as well
    ADPC = 0x09U;   //DEFAULT is all AINx pins are Analog, change 8-15
                    // to digital
    P15 &= ~(1<<MODEM_PHON_PIN); //SET LOW
    PM15 &= ~(1<<MODEM_PHON_PIN); //SET AS OUTPUT
    P15 |= (1<<MODEM_PHON_PIN);  //SET HIGH
    MSTimerDelay(500); //pulse
    P15 &= ~(1<<MODEM_PHON_PIN); //SET LOW
    PM15 |= (1<<MODEM_PHON_PIN); //SET AS INPUT
    
    // wait for modem to power up
    DisplayLCD(LCD_LINE1, "Waiting for ");
    DisplayLCD(LCD_LINE2, "  Modem to  ");
    DisplayLCD(LCD_LINE3, " Initialize ");
    DisplayLCD(LCD_LINE4, "      3     ");
    MSTimerDelay(1000);
    DisplayLCD(LCD_LINE4, "      2     ");
    MSTimerDelay(1000);
    DisplayLCD(LCD_LINE4, "      1     ");
    MSTimerDelay(1000);
    DisplayLCD(LCD_LINE4, "");
    // Start UART0 for Novatel modem
    UART0_Start(NOVATEL_UART_BAUD_RATE);

   

    /* If the CIK is exist, auto into the Exosite mode */
    NVSettingsLoad(&GNV_Setting);
    
    
   

    if(AppMode == RUN_EXOSITE)
    {
        LCDDisplayLogo();
        LCDSelectFont(FONT_SMALL);
        DisplayLCD(LCD_LINE3, "RL78G14 RDK    V2.0");
        DisplayLCD(LCD_LINE4, "   Cellular        ");
        DisplayLCD(LCD_LINE5, "     demos by:     ");
        DisplayLCD(LCD_LINE6, "Novatel            ");
        DisplayLCD(LCD_LINE7, "Exosite            ");
        MSTimerDelay(3500);
        ClearLCD();
        DisplayLCD(LCD_LINE1, "Demo Modes:        ");
        DisplayLCD(LCD_LINE2, "-RST no key:       ");
        DisplayLCD(LCD_LINE3, "   ExoSite App     ");
        DisplayLCD(LCD_LINE4, "-RST + SW1 & SW3:  ");
        DisplayLCD(LCD_LINE5, "   Reset NVM       ");
        DisplayLCD(LCD_LINE6, "-RST + SW1:        ");
        DisplayLCD(LCD_LINE7, "   Cell Activate   ");
        MSTimerDelay(3000);
        ClearLCD();

        LCDSelectFont(FONT_LARGE);
        DisplayLCD(LCD_LINE1, "Exosite DEMO");
        
        Temperature_Init();
        Potentiometer_Init();
        
        App_Exosite();
    }
    else if (AppMode == ACTIVATE_MODEM)
    {
        ATModem_CellActivate();
    }

   

    return 0;
}
Exemplo n.º 20
0
void Lcd_Init(void)
{
	//SPIv_Init();
	SPI2_Init();
	Lcd_Reset();
		    lcddev.width=320;
    lcddev.height=240;
	Lcd_WriteIndex(0xCB);  
        Lcd_WriteData(0x39); 
        Lcd_WriteData(0x2C); 
        Lcd_WriteData(0x00); 
        Lcd_WriteData(0x34); 
        Lcd_WriteData(0x02); 

        Lcd_WriteIndex(0xCF);  
        Lcd_WriteData(0x00); 
        Lcd_WriteData(0XC1); 
        Lcd_WriteData(0X30); 
 
        Lcd_WriteIndex(0xE8);  
        Lcd_WriteData(0x85); 
        Lcd_WriteData(0x00); 
        Lcd_WriteData(0x78); 
 
        Lcd_WriteIndex(0xEA);  
        Lcd_WriteData(0x00); 
        Lcd_WriteData(0x00); 
 
        Lcd_WriteIndex(0xED);  
        Lcd_WriteData(0x64); 
        Lcd_WriteData(0x03); 
        Lcd_WriteData(0X12); 
        Lcd_WriteData(0X81); 

        Lcd_WriteIndex(0xF7);  
        Lcd_WriteData(0x20); 
  
        Lcd_WriteIndex(0xC0);    //Power control 
        Lcd_WriteData(0x23);   //VRH[5:0] 
 
        Lcd_WriteIndex(0xC1);    //Power control 
        Lcd_WriteData(0x10);   //SAP[2:0];BT[3:0] 
 
        Lcd_WriteIndex(0xC5);    //VCM control 
        Lcd_WriteData(0x3e); //对比度调节
        Lcd_WriteData(0x28); 
 
        Lcd_WriteIndex(0xC7);    //VCM control2 
        Lcd_WriteData(0x86);  //--
 
        Lcd_WriteIndex(0x36);    // Memory Access Control 
#ifdef H_VIEW
        Lcd_WriteData(0xE8); //C8	   //48 68竖屏//28 E8 横屏
#else
				Lcd_WriteData(0x48); 
#endif

        Lcd_WriteIndex(0x3A);    
        Lcd_WriteData(0x55); 

        Lcd_WriteIndex(0xB1);    
        Lcd_WriteData(0x00);  
        Lcd_WriteData(0x18); 
 
        Lcd_WriteIndex(0xB6);    // Display Function Control 
        Lcd_WriteData(0x08); 
        Lcd_WriteData(0x82);
        Lcd_WriteData(0x27);  
 
        Lcd_WriteIndex(0xF2);    // 3Gamma Function Disable 
        Lcd_WriteData(0x00); 
 
        Lcd_WriteIndex(0x26);    //Gamma curve selected 
        Lcd_WriteData(0x01); 
 
        Lcd_WriteIndex(0xE0);    //Set Gamma 
        Lcd_WriteData(0x0F); 
        Lcd_WriteData(0x31); 
        Lcd_WriteData(0x2B); 
        Lcd_WriteData(0x0C); 
        Lcd_WriteData(0x0E); 
        Lcd_WriteData(0x08); 
        Lcd_WriteData(0x4E); 
        Lcd_WriteData(0xF1); 
        Lcd_WriteData(0x37); 
        Lcd_WriteData(0x07); 
        Lcd_WriteData(0x10); 
        Lcd_WriteData(0x03); 
        Lcd_WriteData(0x0E); 
        Lcd_WriteData(0x09); 
        Lcd_WriteData(0x00); 

        Lcd_WriteIndex(0XE1);    //Set Gamma 
        Lcd_WriteData(0x00); 
        Lcd_WriteData(0x0E); 
        Lcd_WriteData(0x14); 
        Lcd_WriteData(0x03); 
        Lcd_WriteData(0x11); 
        Lcd_WriteData(0x07); 
        Lcd_WriteData(0x31); 
        Lcd_WriteData(0xC1); 
        Lcd_WriteData(0x48); 
        Lcd_WriteData(0x08); 
        Lcd_WriteData(0x0F); 
        Lcd_WriteData(0x0C); 
        Lcd_WriteData(0x31); 
        Lcd_WriteData(0x36); 
        Lcd_WriteData(0x0F); 
 
        Lcd_WriteIndex(0x11);    //Exit Sleep 
        delay_ms(120); 
				
        Lcd_WriteIndex(0x29);    //Display on 
        Lcd_WriteIndex(0x2c); 

}
Exemplo n.º 21
0
bool CC2500_Init(void)
{
	GPIO_InitTypeDef GPIO_InitStructure;
	NVIC_InitTypeDef NVIC_InitStructure;
	EXTI_InitTypeDef EXTI_InitStructure;  
	u8 i = 0;
	u16 Id;
	
	//CS
	GPIO_InitStructure.GPIO_Pin = CC_CS_IO_PIN;
	GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
	GPIO_Init(CC_CS_IO_GROUP, &GPIO_InitStructure);
	
	SPI2_Init();
	
	CC2500_Reset();
	if((Id=CC2500_GetChipId())!=0x8003)
	{
		Debug("Error CC2500 ID: %04x\n\r",Id);
		return FALSE;
	}
	
	CC2500_RfSettings();

	CC2500_Select();
	CC2500_WriteByte(CCxxx0_PATABLE|WRITE_BURST);
	for(i=0;i<8;i++)
	{
		CC2500_WriteByte(paTable_CC2500[i]);
	}
	CC2500_NoSelect();

	CC2500_SetRxd();

	//GDO0
	GPIO_InitStructure.GPIO_Pin = CC_GDO0_IO_PIN;
	GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
	GPIO_Init(CC_GDO0_IO_GROUP, &GPIO_InitStructure);

#if QXW_LCM_ID == 210 || QXW_LCM_ID == 211 || QXW_LCM_ID == 220 || QXW_LCM_ID == 221
	NVIC_InitStructure.NVIC_IRQChannel = EXTI3_IRQn;
	NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = EXTI3_IRQn_Priority;
	NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0
	NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE
	NVIC_Init(&NVIC_InitStructure);
	
	EXTI_InitStructure.EXTI_Line = EXTI_Line3;             //外部中断线 ,使用第2根
	EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;    //中断模
	EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;//中断触发方式
	EXTI_InitStructure.EXTI_LineCmd = ENABLE;              //打开中断
	EXTI_Init(&EXTI_InitStructure);    //调用库函数给寄存器复制

	CC2500_InterruptEnable(FALSE);
	
	GPIO_EXTILineConfig(GPIO_PortSourceGPIOD, GPIO_PinSource3); 
#elif QXW_LCM_ID == 212
	NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQn;
	NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = EXTI9_5_IRQn_Priority;
	NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0
	NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE
	NVIC_Init(&NVIC_InitStructure);
	
	EXTI_InitStructure.EXTI_Line = EXTI_Line6;             //外部中断线 ,使用第2根
	EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;    //中断模
	EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;//中断触发方式
	EXTI_InitStructure.EXTI_LineCmd = ENABLE;              //打开中断
	EXTI_Init(&EXTI_InitStructure);    //调用库函数给寄存器复制

	CC2500_InterruptEnable(FALSE);
	
	GPIO_EXTILineConfig(GPIO_PortSourceGPIOD, GPIO_PinSource6); 
#endif
	return TRUE;
}
Exemplo n.º 22
0
int  main(void)
{
    AppMode_T AppMode; APP_STATE_E state=UPDATE_TEMPERATURE; 
    char LCDString[30], temp_char[2]; uint16_t temp; float ftemp;
  
    HardwareSetup();

    /************************initializa LCD module********************************/
    SPI2_Init();
    InitialiseLCD();
    led_init();
    MSTimerInit();

    /* Default app mode */
    AppMode = GAINSPAN_DEMO;
    
    /* If the CIK is exist, auto into the Exosite mode */
    NVSettingsLoad(&GNV_Setting);
    
    /* Determine if SW1 & SW3 is pressed at power up to enter programming mode */
    if (Switch1IsPressed() && Switch3IsPressed()) {
         AppMode = PROGRAM_MODE;
    }
    else if(Switch3IsPressed() && Switch2IsPressed())
    {
         AppMode = EXOSITE_ERASE;
    }
    else if(Switch1IsPressed())
    {
        AppMode = RUN_EXOSITE;
    }
    else if(Switch2IsPressed())
    {
        AppMode = RUN_PROVISIONING;
    }
    else if(Switch3IsPressed())
    {
        AppMode = RUN_OVER_AIR_DOWNLOAD;
    }
    
    if(AppMode == GAINSPAN_DEMO) {
        LCDDisplayLogo();
        LCDSelectFont(FONT_SMALL);
        DisplayLCD(LCD_LINE3, "RL78G14 RDK    V2.0");
        DisplayLCD(LCD_LINE4, "   Wi-Fi & Cloud   ");
        DisplayLCD(LCD_LINE5, "     demos by:     ");
        DisplayLCD(LCD_LINE6, "Gainspan           ");
        DisplayLCD(LCD_LINE7, "Exosite            ");
        DisplayLCD(LCD_LINE8, "Future Designs, Inc");
        MSTimerDelay(3500);
        ClearLCD();
        DisplayLCD(LCD_LINE1, "Demo Modes:        ");
        DisplayLCD(LCD_LINE2, "-RST no key:       ");
        DisplayLCD(LCD_LINE3, "   GS Web Server   ");
        DisplayLCD(LCD_LINE4, "-RST + SW1:        ");
        DisplayLCD(LCD_LINE5, "   Exosite Cloud   ");
        DisplayLCD(LCD_LINE6, "-RST + SW2:        ");
        DisplayLCD(LCD_LINE7, "   AP Provisioning ");
        DisplayLCD(LCD_LINE8, "-RST + SW3: OTA    ");
        MSTimerDelay(3000);
        ClearLCD();
        
        LCDSelectFont(FONT_LARGE);
        if(Exosite_GetCIK(NULL))
        {
          AppMode = RUN_EXOSITE;
        }
    }
    
    DisplayLCD(LCD_LINE1, "Starting..."); 
    /*****************************************************************************/  
    SPI_Init(GAINSPAN_SPI_RATE);  
   /* Setup LCD SPI channel for Chip Select P10, active low, active per byte  */
    SPI_ChannelSetup(GAINSPAN_SPI_CHANNEL, false, true);
    GainSpan_SPI_Start();

    PM15 &= ~(1 << 2);
    P15 &= ~(1 << 2);
    
    if(AppMode == PROGRAM_MODE) {
        App_ProgramMode();
    }
    else if (AppMode == RUN_EXOSITE)
    {          
        DisplayLCD(LCD_LINE1, " CLOUD DEMO ");
        Temperature_Init();
        Potentiometer_Init();  
        App_Exosite();
    }
    else if(AppMode == RUN_PROVISIONING)
    {
      App_WebProvisioning();
    }
     else if(AppMode == RUN_OVER_AIR_DOWNLOAD)
    {
       App_OverTheAirProgrammingPushMetheod();
    }
    else if (AppMode == EXOSITE_ERASE)
    {
       ClearLCD();
       LCDSelectFont(FONT_SMALL);
       DisplayLCD(LCD_LINE3, "EEPROM ERASING ... ");
       MSTimerDelay(2000);
       Exosite_Init("renesas", "rl78g14", IF_WIFI, 1);
       DisplayLCD(LCD_LINE3, "                   ");
       DisplayLCD(LCD_LINE4, "Please reset device");
       while(1);
    }
    else{
        UART0_Start(GAINSPAN_CONSOLE_BAUD);
       // UART2_Start(GAINSPAN_UART_BAUD);
 
        Temperature_Init();
        Potentiometer_Init();
    
       // sprintf(LCDString, "RDK Demo %s", VERSION_TEXT);
       // DisplayLCD(LCD_LINE1, (const uint8_t *)LCDString);
   
        /* Before doing any tests or apps, startup the module */
        /* and nonvolatile stettings */
        App_Startup();
        // Now connect to the system
        //App_Connect(&G_nvsettings.webprov);
     
       //  App_PassThroughSPI();
         
         /******************Start Processing Sensor data******************/
         
         uint32_t start = MSTimerGet();  uint8_t c;
         Accelerometer_Init();
         while(1) 
         { 
          // if (GainSpan_SPI_ReceiveByte(GAINSPAN_SPI_CHANNEL, &c)) 
           if(App_Read(&c, 1, 0)) 
             AtLibGs_ReceiveDataProcess(c);
                   
        /* Timeout? */
           if (MSTimerDelta(start) >= 100)     // every 100 ms, read sensor data
           {  
              led_task();
              switch(state)
              {              
                case UPDATE_TEMPERATURE:         
                // Temperature sensor reading
                  temp = Temperature_Get();
#if 0                 
                   // Get the temperature and show it on the LCD
                  temp_char[0] = (int16_t)temp / 16;
                  temp_char[1] = (int16_t)((temp & 0x000F) * 10) / 16;
#endif 
                  temp_char[1] = (temp & 0xFF00)>>8;
                  temp_char[0] = temp & 0xFF;
                  
                  ftemp = *(uint16_t *)temp_char;
                  
                  gTemp_F = ((ftemp/5)*9)/128 + 22;
              
                  // Display the contents of lcd_buffer onto the debug LCD 
                  //sprintf((char *)LCDString, "TEMP: %d.%d C", temp_char[0], temp_char[1]);
                  sprintf((char *)LCDString, "TEMP: %.1fF", gTemp_F);
                  DisplayLCD(LCD_LINE6, (const uint8_t *)LCDString);  
                  state = UPDATE_LIGHT;
                break;
                
                case UPDATE_LIGHT:
                 // Light sensor reading
                  gAmbientLight = LightSensor_Get();
                    // Display the contents of lcd_buffer onto the debug LCD 
                  sprintf((char *)LCDString, "Light: %d ", gAmbientLight);
                  DisplayLCD(LCD_LINE7, (const uint8_t *)LCDString);
                  state = UPDATE_ACCELEROMETER;
                break;
                
                case UPDATE_ACCELEROMETER: 
                 // 3-axis accelerometer reading
                  Accelerometer_Get();
                  sprintf((char *)LCDString, "x%2d y%2d z%2d", gAccData[0], gAccData[1], gAccData[2]);
                  DisplayLCD(LCD_LINE8, (const uint8_t *)LCDString); 
                  state = UPDATE_TEMPERATURE;
                break;
              }
              start = MSTimerGet();
           }
         }          
    }    
Exemplo n.º 23
0
////////////////////////////////////////////////////////////////////////////////
//移植时候的接口
void SPI_INIT(void)
{
	SPI2_Init();
}