Esempio n. 1
0
void initializeSystem(void) {
    CyGlobalIntEnable;
    
    UART_Start(); 
    
    PrISM_1_Start();
    PrISM_2_Start();
    
    Opamp_1_Start();
    
    // Start the Bluetooth Stack
    CyBle_Start(CustomEventHandler);	
    
    // Set up the LED. First set its output to be off so that the LED doesn't blink on.
    // Then set the drive mode to strong.
	PrISM_1_WritePulse0(255);
	PrISM_1_WritePulse1(255);
	PrISM_2_WritePulse0(255);
	
	RED_SetDriveMode(RED_DM_STRONG);
	GREEN_SetDriveMode(GREEN_DM_STRONG);
	BLUE_SetDriveMode(BLUE_DM_STRONG);
    
    // Start the ADC
    ADC_SAR_Seq_Start();
    ADC_SAR_Seq_StartConvert();
    ADC_SAR_Seq_IRQ_Enable();
    // Enable an interupt for when the ADC has data
    ADC_SAR_Seq_IRQ_StartEx(ADC_SAR_Seq_ISR_LOC);
    
    // Start the Timer for the ADC
    ADC_Timer_Start();
    
    elapsed = 0;
}
Esempio n. 2
0
/*******************************************************************************
* Function Name: CyBtldrCommStart
********************************************************************************
*
* Summary:
*  Starts the UART communication component 
*
* Parameters:  
*  void
*
* Return: 
*  void 
*
* Side Effects:
*   None  
*
*******************************************************************************/
void CyBtldrCommStart(void)
{        
	/* Start UART component and clear the TX,RX buffers */
	UART_Start();
	UART_SpiUartClearRxBuffer();
	UART_SpiUartClearTxBuffer();
}
Esempio n. 3
0
/***********************************Main***********************************/
int main()
{
    int16 mav_data;
    ADC_ISR_StartEx(ADC_interrupt);
    CyGlobalIntEnable;
    UART_Start();                       /* Initialize ADC */    
    ADC_Start();                        /* Initialize ADC */
    ADC_StartConvert();                 /* Start ADC conversions */
    ADC_IRQ_Enable();                   /* Enable ADC interrupts */    
    
    for (;;)
    {      
        if(data_ready)
        {  
            mav_data = mavg_filter(accgroen);
            gradergroen = grader(mav_data);
            //UART_UartPutChar(mav_data);
            //UART_UartPutChar(mav_data>>8);
            UART_UartPutChar(gradergroen);
            UART_UartPutChar(gradergroen>>8);

            data_ready = FALSE;
        }
    }
}
Esempio n. 4
0
int main()
{
    /* Place your initialization/startup code here (e.g. MyInst_Start()) */
    ADC_DelSig_Start();
    AMux_Start();
    UART_Start();
    CyGlobalIntEnable; /* Uncomment this line to enable global interrupts. */
   // LCD_Char_Start();
    //status = LCD_SegStat_Start();
    CyDelay(10000u); //10 second delay to allow for sensors to "warm up"
    //uint8 buffer[50];
    //uint8 buffer2[50];
    uint8 value[128];
    for(;;)
    {
        /* Place your application code here. */
        Radiation rad;
        rad = take_radiation_reading();
        Vaisala vais;
        vais = take_Temp_RH_reading();
        //LCD_Char_ClearDisplay();
        //LCD_Char_Position(0u, 0u);
        //sprintf(buffer,"%d %d %d %d", (int)fake.SW_In, (int)fake.SW_Out, (int)fake.LW_In, (int)fake.LW_Out);
        //LCD_Char_PrintString(buffer);
        //LCD_Char_Position(1u, 0u);
        //sprintf(buffer2,"%d %d",(int)fake2.Temp, (int)fake2.RH);
        //LCD_Char_PrintString(buffer2);
        sprintf(value,"%d,%d,%d,%d,%d,%d,%d\r\n",(int)rad.SW_In, (int)rad.SW_Out, (int)rad.LW_In, (int)rad.LW_Out,(int)((rad.temp-273.15)*100),  (int)(vais.Temp*100), (int)(vais.RH*100));
        UART_PutString(value);
        uint8 x = 0;
    }
}
Esempio n. 5
0
void initPSoC_Master(void){
	tempTemp = 0;
    tempSoilHum[0] = 0;
    tempSoilHum[1] = 0;
    tempSoilHum[2] = 0;
    tempSoilHum[3] = 0;
    tempSoilHum[4] = 0;
    tempSoilHum[5] = 0;
	
    // ISR
    UART_ISR_StartEx(UART_ISR);     // Starts UART interrupt component
    timer_ISR_StartEx(timer_ISR);   // Starts timer interrupt component
    
    UART_Start();                   //  Starts UART component
    Timer_Start();                  // Starts timer component
    
    // Setup of timer interrupt
    uint32 maxPeriod = 0xFFFFFFFF;  // The max period ((2^32)-1) = 179s
    uint32 period = TIME_BETWEEN_TIMER_INT * 24000;
    
    if (period > maxPeriod){
        period = maxPeriod;
    }
    
    Timer_WritePeriod(period);
    
    RedLED_Write(LED_OFF);              // Turn off red LED
    BlueLED_Write(LED_OFF);             // Turn off blue LED

}
Esempio n. 6
0
void main(void)
{
	// Insert your main routine code here.
	unsigned char c = 0;
	M8C_EnableGInt;
	UART_EnableInt();
	UART_Start(UART_PARITY_NONE);
	PGA_1_Start(PGA_1_HIGHPOWER);
	ADCINC_Start(ADCINC_HIGHPOWER); // Apply power to the SC Block
	ADCINC_GetSamples(0);
	DAC6_Start(DAC6_HIGHPOWER);
	PWM8_DisableInt();
	PWM8_Start();
	for(;;)
	{
		PWM8_WritePulseWidth(m_to_s_mem[0]);
		DAC6_WriteBlind(m_to_s_mem[1]); 
		//if ( DELSIG8_bfStatus ) {
		//	DELSIG8_bfStatus = 0;
		//	s_to_m_mem[0] = DELSIG8_cResult;
		//}
		//ADCINC_GetSamples(1);
		//while(ADCINC_fIsDataAvailable() == 0);
		//s_to_m_mem[0] = ADCINC_bClearFlagGetData(); 
	}
	//mainloop:
	//	UART_SendData(temp++);
		//while( ++temp2 );
	//goto mainloop;
}
bool UART_CustomPortEnable(void)
{
  UART_Start();
  pinMode(D0, PERIPHERAL_IN);
  pinMode(D1, PERIPHERAL_OUT);
  return true; 
}
Esempio n. 8
0
/*******************************************************************************
* 初始化函数
********************************************************************************/
void init()
{
    CyGlobalIntEnable; //全局中断开启
    
    ADC_DelSig_1_Start();  /* 配置并开启ADC */
    ADC_DelSig_1_StartConvert(); /* 开始进行转换 */
    
    Uart_Rx_ISR_StartEx(RxInterruptHandler);      /* 开启 Uart Rx 中断 并连接到 RxInterruptHandler */
    Uart_Tx_ISR_StartEx(TxInterruptHandler);      /* 开启 Uart Tx 并连接到 TxInterruptHandler */
    UART_Start();     /* 开启 UART */
    
    Uart_Rx_ISR_1_StartEx(Rx_1_InterruptHandler);      /* 开启 Uart Rx 中断 并连接到 RxInterruptHandler */
    Uart_Tx_ISR_1_StartEx(Tx_1_InterruptHandler);      /* 开启 Uart Tx 并连接到 TxInterruptHandler */
    UART_1_Start();     /* 开启 UART1 */
    
    Uart_Rx_ISR_2_StartEx(Rx_1_InterruptHandler);      /* 开启 Uart Rx 中断 并连接到 RxInterruptHandler */
    Uart_Tx_ISR_2_StartEx(Tx_1_InterruptHandler);      /* 开启 Uart Tx 并连接到 TxInterruptHandler */
    UART_2_Start();     /* 开启 UART2 */
    
    
    Timer_ISR_StartEx(TimerInterruptHandler); /* 开启 Timer 中断并连接到 TimerInterruptHandler */
    Timer_Start();          /* 开启定时器 */
    
    LCD_Char_1_Start(); /* 初始化并清除LCD */
    //LCD_Char_1_PrintString("init");
}
Esempio n. 9
0
int main()
{   
    char out_buffer[32];
    
    CyGlobalIntEnable; /* Enable global interrupts. */
    isr_wire_StartEx(wireHandler);
    isr_uart_StartEx(uartHandler);
    isr_stop_StartEx(stopHandler);
    isr_wstart_StartEx(wstartHandler);
    isr_ustart_StartEx(ustartHandler);
    UART_Start();

    uint16_t counter1, counter2;
    for(;;)
    {
        counter1 = Timer_wire_ReadCounter();
        sprintf(out_buffer,"Wired: %i:%i:%i:%i\n\r",wire.hour,wire.min,wire.sec, counter1);
        UART_PutString(out_buffer);
        counter2 = Timer_uart_ReadCounter();
        sprintf(out_buffer,"Xbee:  %i:%i:%i:%i\n\r",uart.hour,uart.min,uart.sec, counter2);
        UART_PutString(out_buffer);
        sprintf(out_buffer, "delta = %i\n\n\r", Timer_wire_ReadCounter()-Timer_uart_ReadCounter());
        UART_PutString(out_buffer);
        CyDelay(500);
       
        
    }
}
Esempio n. 10
0
int main()
{
    char c;    
    int note=0; // current Notes
    int printFlag=0; // if set to 0 it prints the notes when they change
 
    CyGlobalIntEnable; /* Enable global interrupts. */
    CySysTickStart();
    
    Music_Start(0);
 
    UART_Start();
   
    sprintf(buff,"Started\n");
    UART_UartPutString(buff);

    for(;;)
    {
        c = UART_UartGetChar();
        switch(c)
        {
            case 's':
                UART_UartPutString("Start\n");
                Music_PlaySong(0);
            break;
            case 'S':
                UART_UartPutString("Stop\n");
                Music_Stop();
            break;
            case 'p':
                printFlag=0;
                break;
            case 'P':
                printFlag = 1;
            break;
            case 't': // put it back to the default
                Music_SetBPM(0);
            break;
            case 'T':
                Music_SetBPM(60);
            break;
                
            case '1':
                Music_PlaySong(0);
            break;
            case '2':
                Music_PlaySong(1);
            break;
        }
        
        if(note != Music_GetNote() && printFlag)
        {
            note = Music_GetNote();
            sprintf(buff,"Note = %d\n",note);
            UART_UartPutString(buff);
        }
    }
}
Esempio n. 11
0
int main()
{
    CyGlobalIntEnable;                  /* Enable global interrupts */
    UART_RX_ISR_StartEx(RX_interrupt);  /* Set interrupt address */
    UART_BLE_RX_ISR_StartEx(BLE_RX_interrupt);  /* Set interrupt address */
    UART_Start();                       /* Start UART */
    UART_BLE_Start();                       /* Start UART */
    CySysPmSleep();                     /* Enter Sleep mode */
    return 0;
}
Esempio n. 12
0
//start the relevant components
void hardware_init() {
    PWM_Front_Start();
    PWM_Rear_Start();
    QuadDec_Front_Start();
    QuadDec_Rear_Start();
    QuadDec_Front_TriggerCommand(QuadDec_Front_MASK, QuadDec_Front_CMD_RELOAD);
    QuadDec_Rear_TriggerCommand(QuadDec_Rear_MASK, QuadDec_Rear_CMD_RELOAD);
    UART_Start();
    Motor_Current_ADC_Start();

}
Esempio n. 13
0
void serial_init(void)
{	
	UART_CmdReset(); // Initialize receiver/cmd
	// buffer
	UART_IntCntl(UART_ENABLE_RX_INT); // Enable RX interrupts
	Counter8_WritePeriod(155); // Set up baud rate generator
	Counter8_WriteCompareValue(77);
	Counter8_Start(); // Turn on baud rate generator
	UART_Start(UART_PARITY_NONE); // Enable UART
	
	serial_cprint("\r\n:: Welcome to Kelvin [v0.1.1] ::");
}
Esempio n. 14
0
void init_uart(void){
	///UART////      

    UART_CmdReset(); 
    UART_IntCntl(UART_ENABLE_RX_INT);       
    UART_Start(UART_PARITY_NONE);            
    UART_PutChar(12);
	
	#ifdef UART_VERBOSE
	UART_CPutString("\r\n\r\n\r\n\r\n\r\n\r\n waking up......................................."); 
	#endif
}
Esempio n. 15
0
void main(void)
{
	char opt;
	
	// Make sure nCS is high before doing anything
	nCS_HIGH;
	
	// Enable user module interrupts
	SleepTimer_EnableInt();

	// Enable global interrutps
	M8C_EnableGInt;

	// Start the user modules
	UART_Start(UART_PARITY_NONE);
	UART_PutCRLF();
	SPIM_Start(SPIM_SPIM_MODE_0 | SPIM_SPIM_MSB_FIRST);
	SleepTimer_Start();
	DAC8_Start(DAC8_FULLPOWER);
	UART_CPutString("Synthesiszing waveforms\r\n");
	WriteBlock(0);
	WriteBlock(1);
	WriteBlock(2);
	WriteBlock(3);
	while(1) 
	{
		UART_CPutString("Synthetic wave output is on Port0[4]\r\nCowabunga Dude! Time to catch some waves.\r\n\r\n0. Play block 0\r\n1. Play block 1\r\n2. Play block 2\r\n3. Play block 3\r\n4. Test status register\r\n5. Test byte mode\r\n6. Test sequential mode\r\n");
		
		opt = GetNumber(0, 6);
		switch (opt)
		{
			case 4:
				while(SPIRAM_StatusRegisterTest()) 
					SleepTimer_SyncWait(4, SleepTimer_WAIT_RELOAD);
				break;
			
			case 5:
				while(SPIRAM_ByteModeTest()) 
					SleepTimer_SyncWait(4, SleepTimer_WAIT_RELOAD);	
				break;
			
			case 6:
				while(SPIRAM_SequentialModeTest()) 
					SleepTimer_SyncWait(4, SleepTimer_WAIT_RELOAD);
				break;
			
			default:
				PlayBlock(opt);
				break;	
		}
	}
}
Esempio n. 16
0
void main(){
	CYGlobalIntDisable;//Disable interrupts to avoid triggering during setup.
    LCD_Start();// Start LCD.
	UART_Start();// Start UART.
	Rx_Int_Start();//Start the Interrupt.
	Rx_Int_SetVector(Rx_ISR);//Set the Vector to the ISR.
	LCD_PrintString("UART:RX ISR Demo");//Print to the LCD.
	UART_PutString("UART:RX ISR Demo");//Print to Serial Terminal.
	CyDelay(1000);
	LCD_ClearDisplay();//Clear the screen for RX Data.
	CYGlobalIntEnable;//Enable Interrupts,and let the Games begin!
	
    for(;;);
}
Esempio n. 17
0
uint8_t cypressInit(void){
	WIZ_RST_Write(1);
	SPIM_Start();
	UART_Start();
	init_printf(NULL,putdata);
	
	
	//if(SW1_Read()) {  // if button is not being pressed
            
	LED_Write(0); // turn LED off
	
	
	
	CyGlobalIntEnable;
	return 1;
}
Esempio n. 18
0
void main_test_display(){
    UART_Start();                       // initialize UART
    UART_PutChar(0x81); // init connection; set to 16x12 image 
    
    struct disp_grid_81 disp; 
    disp_grid_init(&disp,0x3F); // init our display grid matrix to white  
    disp_grid_transmit(&disp);
    
    struct tic_tac_ai tta;
    tta_init(&tta,4,3,false,true); //first bool for player 1, second bool for player 2. true means is AI
    disp_grid_init_ttc(&disp, tta.game.grid);
    
    disp_grid_draw_tic(&disp,24,1,0x27); // draw tic
    disp_grid_draw_win(&disp,27,9,1); // draw tic
    disp_grid_draw_xia(&disp,26,16,0x30); // draw xia
    disp_grid_transmit(&disp);
}
Esempio n. 19
0
int main()
{

	// striplights component init
    StripLights_Start();
	
	/* Start UART component and clear the TX,RX buffers */
	UART_Start();
	UART_SpiUartClearRxBuffer();

	// Switch on ESP8266's PD function
	CH_PD_SetDriveMode(CH_PD_DM_STRONG ) ;
	CH_PD_Write(1);

	// start UART for esp wifi 
	uWIFI_Start();
	uWIFI_SpiUartClearRxBuffer();
    
	CyGlobalIntEnable;  /* Un/comment this line to dis/enable global interrupts. */

	// LED output
	P1_6_SetDriveMode(P1_6_DM_STRONG ) ;
	
	// LED on.
	P1_6_Write(1);
	
	//cycle each of the primaries on all LED's, DisplayClear sets and pushes to LED's, MemoryClear just clears the buffer.
	StripLights_DisplayClear( StripLights_RED_MASK );	CyDelay( 500 ); 
	StripLights_DisplayClear( StripLights_GREEN_MASK );	CyDelay( 500 ); 
	StripLights_DisplayClear( StripLights_BLUE_MASK );	CyDelay( 500 ); 

	// Set to off
	StripLights_DisplayClear( 0 );

	// uncomment for echo back, useful to setup ESP8266 as well
	//echo_uart();
	
	run_server();
	
	
	//reboot on return
    CySoftwareReset();
    
    return 0;
}
Esempio n. 20
0
void main_play_ttc(){
    LCD_Start();					    // initialize lcd
    LCD_ClearDisplay();
    UART_Start();                       // initialize UART
    UART_PutChar(0x81); // init connection; set to 16x12 image 
    
    struct disp_grid_81 disp; 
    disp_grid_init(&disp,0x3F); // init our display grid matrix to white  
    disp_grid_transmit(&disp);
    
    struct tic_tac_toe lolz;
 	ttc_init(&lolz,4,3);    
    disp_grid_init_ttc(&disp,lolz.grid); // init the board
    disp_grid_draw_xia(&disp,26,16,0x30); // draw xia
    disp_grid_transmit(&disp);
    
    int x,y,z; int Values;
    
    while (lolz.game_not_won == 0){
        //Values = read_from_8255(Values);
        Values = Pin3_Read();
        if (Values >= 0 && Values <= 63){ //integer value
            z = Values / 16;
            x = Values % 4; //get row value
            y = Values / 4 - z*4; // 
            LCD_ClearDisplay();
            LCD_PrintNumber(Values);
            LCD_PrintString(" x");
            LCD_PrintNumber(x);
            LCD_PrintString(" y");
            LCD_PrintNumber(y);
            LCD_PrintString(" z");
            LCD_PrintNumber(z);
        }
        if (ttc_get_grid(&lolz,x,y,z) == 0){ // has not been accessed
            ttc_step(&disp,&lolz,x,y,z); // step & print
            disp_grid_transmit(&disp);
        }
        
    }
    LCD_ClearDisplay();
    LCD_Position(0,0); //move to bot row
    LCD_PrintString("GAME OVER!");    
    
}
Esempio n. 21
0
int main()
{
    char c;    
    int note=0; // current note
    int printFlag=0; // if set to 0 it prints the notes when they change
 
    CyGlobalIntEnable;
    CySysTickStart();
    Music_Start(0);
    UART_Start();
    UART_UartPutString("Started\n");

    Music_AddSong(1,&scale);
    
    for(;;)
    {
        c = UART_UartGetChar();
        switch(c)
        {
            #ifdef Music_TWOCHANNELS
            case 'b': Music_BuzzOn(300,0);    break; // turn on the buzzer 1
            case 'B': Music_BuzzOff();        break; // turn off the buzzer 1
            case 'n': Music_BuzzOn(200,500);  break; // turn on the buzzer for 500ms
            #endif
            case 'p': printFlag=0;            break; // turn off the note printer
            case 'P': printFlag = 1;          break; // turn on the note printer
            case 't': Music_SetBPM(0);        break; // Put the song back to the default
            case 'T': Music_SetBPM(60);       break; // Put the current song to 60BPM
            case '1': Music_PlaySong(0,0);    break; // Play the 1st Song
            case '2': Music_PlaySong(1,0);    break; // Play the 2nd Song
            case 's':
                UART_UartPutString("Stop\n");
                Music_Stop();
            break;
        }
        
        if(note != Music_GetNote() && printFlag)
        {
            note = Music_GetNote();
            sprintf(buff,"Note = %d\n",note);
            UART_UartPutString(buff);
        }
    }
}
Esempio n. 22
0
void Initial()
{
	CyGlobalIntEnable;
    //Check_Boot();
    Timer_RTOS_Start();
    PWM_Start();
    I2C_Start();
    UART_Start();
    RTC_Start();
    RTC_SetPeriod(1,1000);
    RTOS_Start();
    SetTask(Brightles_PID_Controll);
    LCD_WS0010Start();
    SetTask(WaitPowerStab);
    SetTimerTask(OPT_Get_Result, 1300);
    //BLE_Status();
    GlobalStruct.OS_Status = 0;
    SetTimerTask(Display_Controll, 2000);
}
Esempio n. 23
0
void main_play_tta_ai(){
    LCD_Start();					    // initialize lcd
    LCD_ClearDisplay();
    UART_Start();                       // initialize UART
    UART_PutChar(0x81); // init connection; set to 16x12 image 
    
    struct disp_grid_81 disp; 
    disp_grid_init(&disp,0x3F); // init our display grid matrix to white  
    disp_grid_transmit(&disp);
    
    int x,y,z; uint8 Values; 
    
    struct tic_tac_ai tta;
    tta_init(&tta,4,3,true,false); //first bool for player 1, second bool for player 2
    disp_grid_init_ttc(&disp, tta.game.grid);
    disp_grid_draw_xia(&disp,26,16,0x30); // draw xia
    disp_grid_transmit(&disp);
    
    while (tta.game.game_not_won == 0){
        Values = read_from_8255(Values); //read and print
        if (Values >= 0 && Values <= 63){ //integer value
            z = Values / 16;
            x = Values % 4; //get row value
            y = Values / 4 - z*4; // 
//            LCD_ClearDisplay();
//            LCD_PrintNumber(Values);
//            LCD_PrintString(" x");
//            LCD_PrintNumber(x);
//            LCD_PrintString(" y");
//            LCD_PrintNumber(y);
//            LCD_PrintString(" z");
//            LCD_PrintNumber(z);
        }
        tta_step(&disp,&tta,x,y,z); //increment a turn
        disp_grid_transmit(&disp);
    }
    LCD_ClearDisplay();
    LCD_PrintString("GAME OVER!");   
    disp_grid_draw_win(&disp,27,9,tta.game.player); // draw tic
    disp_grid_transmit(&disp);
    
}
Esempio n. 24
0
/*******************************************************************************
* Function Name: main
********************************************************************************
*
* Summary:
*  Main function.
*
* Parameters:
*  None
*
* Return:
*  None
*
*******************************************************************************/
int main()
{
    CYBLE_API_RESULT_T apiResult;
    CYBLE_STATE_T bleState;

    CyGlobalIntEnable;
	
    PWM_Start();
	UART_Start();
	UART_UartPutString("Welcome to BLE OOB Pairing Demo\r\n");

    apiResult = CyBle_Start(StackEventHandler);

    if(apiResult != CYBLE_ERROR_OK)
    {
        /* BLE stack initialization failed, check your configuration */
        CYASSERT(0);
    }

    CyBle_IasRegisterAttrCallback(IasEventHandler);

    for(;;)
    {
        /* Single API call to service all the BLE stack events. Must be
         * called at least once in a BLE connection interval */
        CyBle_ProcessEvents();

        bleState = CyBle_GetState();

        if(bleState != CYBLE_STATE_STOPPED &&
            bleState != CYBLE_STATE_INITIALIZING)
        {
            /* Configure BLESS in DeepSleep mode  */
            CyBle_EnterLPM(CYBLE_BLESS_DEEPSLEEP);

            /* Configure PSoC 4 BLE system in sleep mode */
            CySysPmSleep();

            /* BLE link layer timing interrupt will wake up the system */
        }
    }
}
Esempio n. 25
0
int main()
{
    hkj_timer t;
    const uint16 myCharHandle = 0x0E;
    uint8 writeData = 0;
    CYBLE_GATT_VALUE_T writeValue = \
        { &writeData, sizeof(writeData), sizeof(writeData) };
    CYBLE_GATTC_WRITE_REQ_T writeReqParam = \
        { .value = writeValue, .attrHandle = myCharHandle };

    CYBLE_STACK_LIB_VERSION_T stackVersion;

    CyGlobalIntEnable;
    UART_Start();
    hkj_debug_init();
    CyBle_GetStackLibraryVersion(&stackVersion);
    debug_print("Latency Central      Stack: %u.%u.%u.%u\r\n", \
        stackVersion.majorVersion, stackVersion.minorVersion, \
        stackVersion.patch, stackVersion.buildNumber);
    CyBle_Start(BleEventHandler);

    hkj_timer_ms_init(&t);
    while(1)
    {
        CyBle_ProcessEvents();
        if (connHandle.bdHandle != 0)
        {
            if (hkj_timer_ms_get_delta(&t) > 500)
            {
                WRITE_CMD_PIN_Write(1);
                CyBle_GattcWriteWithoutResponse(connHandle, &writeReqParam);
                hkj_timer_ms_reset_delta(&t);
                CyDelay(2); 
                WRITE_CMD_PIN_Write(0);
            }
        }
        hkj_ble_events_log_debug_print();
    }
}
Esempio n. 26
0
void init() {
    
    CyGlobalIntEnable;
    rx_int_StartEx(RX_INT);             // start RX interrupt (look for CY_ISR with RX_INT address)
                                        // for code that writes received bytes to LCD.
    
    UART_Start();                       // initialize UART
    UART_ClearRxBuffer();
    
    // Init Electronic Components
    PGA_TOP_GND_Start();
    PGA_REF_Start();
    PGA_GAIN_Start();
    IDAC8_REF_Start();
    ADC_SAR_1_Start();
    //ADC_SAR_1_StartConvert();
    
    // Init muxes
    TOP_MUX_GND_Start();
    TOP_MUX_VREF_Start();
    BOTTOM_MUX_SENSE_Start();
    zeroAllPins();
}
Esempio n. 27
0
int main()
{
    CyGlobalIntEnable; /* Enable global interrupts. */
    
    // Set up LCD screen
    LCD_Start();
	LCD_ClearDisplay();
    
    rx_isr_StartEx(rx_isr);             // start RX interrupt (look for CY_ISR with RX_INT address)
                                        // for code that writes received bytes to LCD.
    
    UART_Start();                       // initialize UART
    UART_ClearRxBuffer();
    
    // Check status message
    UART_PutString("AT\r\n");
    CyDelay(1000);\
    LCD_ClearDisplay();
    
    // Set name to VizDude
    UART_PutString("AT+NAME=VizDude\r\n");
    CyDelay(1000);\
    LCD_ClearDisplay();
    
    // Set rate to 115200 Baud, 1 stop bit, no parity
    UART_PutString("AT+UART=115200,1,0\r\n");
    CyDelay(1000);\
    LCD_ClearDisplay();

    /* Place your initialization/startup code here (e.g. MyInst_Start()) */

    for(;;)
    {
        /* Place your application code here. */
    }
}
Esempio n. 28
0
int main(void) {
    /* stop the watchdog timer */
    WDTCTL = WDTPW + WDTHOLD;

    /* set up the clocks for 1 mhz */
    BCSCTL1  = CALBC1_1MHZ;       // Set range
    DCOCTL   = CALDCO_1MHZ;
    BCSCTL2 &= ~(DIVS_3);         // SMCLK = DCO / 8 = 1Mhz

    /* LEDs off, but we can use them for debugging if we want */
    P1DIR |= RED_LED+GRN_LED;
    P1OUT &= ~ (RED_LED + GRN_LED );

    initUart();

    /* Start listening for data */
    UART_Start();

    /* enable interrupts */
    __bis_SR_register( GIE );

    uartPrint("\n\rCli Started.\n\r");
    cliHelp();
    uartPrint(PROMPT);

    char in_char;
    while(1) {
        while(rx_size() > 0) {
            in_char = uartGetChar();
            uartPutChar(in_char);
            cli_input(in_char);
        }
        /* go to sleep and wait for data */
        __bis_SR_register( LPM0_bits );
    }
}
void CyBtldrCommStart(void) {
    UART_Start();
}
Esempio n. 30
0
void main(void)
{	
	M8C_EnableGInt ; // Uncomment this line to enable Global Interrupts
	
	// Start the UART(with no parity), and Counter16
	UART_Start(UART_PARITY_NONE);
	// clock for moving serial
	Counter16_Start();
	
	// Start I2CHW
	I2CHW_Start();
	I2CHW_EnableMstr();
	I2CHW_EnableInt();
	
	// This is the command usage string
	UART_CPutString("########################## I2C External SRAM ########################\r\n\
#	W # XX T [Data]\r\n\
#		W    - Write command\r\n\
#		#    - Group Address (0 - 7)\r\n\
#		XX   - Memory Location in hex (00 - FF)\r\n\
#		T    - Data Type, either A for ASCII or H for Hexadecimal\r\n\
#		Data - Either ASCII string or Hexadecimal separates by spaces\r\n\
#\t\t\tA - Mary had a little lamb\r\n\
#\t\t\tH - 01 FF A0 0F D8 C3\r\n\
#\r\n\
#	R # XX T NN\r\n\
#		R    - Read command\r\n\
#		#    - Group Address (0 - 7)\r\n\
#		XX   - Memory Location in hex (00 - FF)\r\n\
#		T    - Data Type, either A for ASCII or H for Hexadecimal\r\n\
#		NN	 - Number of bytes to read in hexadecimal\r\n\
#####################################################################\r\n");
	while (1)
	{
		char *cmd;
		char *params;
		char slaveAddress = 0x50;		// 010100000 R/W shifted to front
		
		GetLine(buf, 79); // Retrieves a line with a maximum length of 70 characters and put it in buf.
		
		memset(data, 0x00, 256);	// Initialize all the set {data} to NULL bytes
		cmd = Lowercase(cstrtok(buf, " ")); // Get the first word from the entered string and lowercase it.
		if (strlen(cmd) == 1 && cmd[0] == 'w') // If the command is one letter and it is w, then write command
		{	
			int groupAddress; // only 1 and 2 actually go to SRAM
			int memLoc;
			char dataType;
			
			int len;

			params = cstrtok(0x00, " ");  // 0x00 indicates it will continue from last cstrtok command and get next word. This gets the next parameter
			
			// csscanf if used to parse the string into values such as hexadecimal or integers
			// It returns the number of parameters it parsed which should be one
			// If the length of the params is not right or it does not parse the right amount, it returns an error
			// %d gets an integer, this is the groupAddress
			if (strlen(params) != 1 || csscanf(params, "%d", &groupAddress) != 1) goto error;
			
			// %x gets a hexadecimal value, this can read capital or lowercase letters, this is the memory location
			params = cstrtok(0x00, " ");
			if (strlen(params) != 2 || csscanf(params, "%x", &memLoc) != 1) goto error;
			
			// %c gets a character, the data type character
			params = cstrtok(0x00, " ");
			if (strlen(params) != 1 || csscanf(params, "%c", &dataType) != 1) goto error;
			
			// This reads the rest of the string and stores it in params. 
			// If the length is zero or if cstrtok returns 0, this means that there was no valid string/hex entered
			params = cstrtok(0x00, "\0");
			if (strlen(params) == 0 || params == 0x00) goto error;	// They did all the params but didn't write anything
			
			dataType = tolower(dataType); // Lowercase the data type
			if (groupAddress < 0 || groupAddress > 7)
				goto error; // groupAddress was not in range
			
			data[0] = memLoc;	// First byte needs to be the memory location according to PCF8570 datasheet
			slaveAddress |= groupAddress;	// ORs the group 2 address to the group 1 address to get slaveAddress
			
			if (dataType == 'a') // If the data type is ASCII
			{
				strcpy((data + 1), params); // Copy the string from params and put it right after the data[0] byte
				len = strlen((data + 1)) + 1; // len is the number of bytes to write, it is the length of the string and then +1 because of the memLoc byte
				// Cant just do strlen(data) because data[0] could be 0x00 and it would return 0 as the string length
			}
			else if (dataType == 'h') // If the data type is hex
			{
				// Take ASCII encoded hex data params and put it after data[0], returns number of bytes converted
				if ((len = HexConversion(params, (data + 1))) == -1)
					goto error;
				len++; // Add one to the length because of the memLoc byte at data[0]
			}
			else
				goto error;
			
			I2CHW_bWriteBytes(slaveAddress, data, len, I2CHW_CompleteXfer); // Write len bytes from data 
			while (!(I2CHW_bReadI2CStatus() & I2CHW_WR_COMPLETE)); // Wait while it is writing
			I2CHW_ClrWrStatus(); // Clear the write bit

			csprintf(data, "%x bytes were written", len); // csprintf takes the string and substitutes %x for len, puts into data str
			UART_PutString(data); // Print the string to UART
			UART_PutCRLF();
		}
		else if (strlen(cmd) == 1 && cmd[0] == 'r') // If the command is one letter and it is r, then read command
		{
			int groupAddress;
			int memLoc;
			char dataType;
			int numBytes;
			
			char hexStr[4];
			int i;

			// csscanf if used to parse the string into values such as hexadecimal or integers
			// It returns the number of parameters it parsed which should be one
			// If the length of the params is not right or it does not parse the right amount, it returns an error
			// %d gets an integer, this is the groupAddress
			params = cstrtok(0x00, " ");
			if (strlen(params) != 1 || csscanf(params, "%d", &groupAddress) != 1) goto error;
	
			// %x gets a hexadecimal value, this can read capital or lowercase letters, this is the memory location
			params = cstrtok(0x00, " ");
			if (strlen(params) != 2 || csscanf(params, "%x", &memLoc) != 1) goto error;
			
			// %c gets a character, the data type character
			params = cstrtok(0x00, " ");
			if (strlen(params) != 1 || csscanf(params, "%c", &dataType) != 1) goto error;
			
			// %x gets a hexadecimal value, number of bytes to read
			params = cstrtok(0x00, " ");
			if (strlen(params) != 2 || csscanf(params, "%x", &numBytes) != 1) goto error;
			
			// If there is any data after the number of bytes, then the format is invalid and it should return an error
			if (cstrtok(0x00, " ") != 0x00) goto error;
			
			dataType = tolower(dataType); // Lowercase the data type
			if (groupAddress < 0 || groupAddress > 7)
				goto error; // groupAddress was not in range
			
			data[0] = memLoc;	// First byte needs to be the memory location according to PCF8570 datasheet
			slaveAddress |= groupAddress;	// ORs the group 2 address to the group 1 address to get slaveAddress
			
			I2CHW_bWriteBytes(slaveAddress, data, 1, I2CHW_NoStop); // Write one byte to the RAM, the slaveAddress so it knows who were talking to
			while (!(I2CHW_bReadI2CStatus() & I2CHW_WR_COMPLETE)); // Wait while it is writing
			I2CHW_ClrWrStatus(); // Clear the write bit
			
			I2CHW_fReadBytes(slaveAddress, data, numBytes, I2CHW_CompleteXfer); // Read numBytes from the RAM, put it in data
			while(!(I2CHW_bReadI2CStatus() & I2CHW_RD_COMPLETE)); // Wait while it is reading
			I2CHW_ClrRdStatus(); // Clear the read bit
			
			if (dataType == 'a') // If the data type is ASCII
			{
				for (i = 0; i < numBytes; ++i) // Loop through each byte
					UART_PutChar(data[i]); // Put the character in PuTTy
				UART_PutCRLF();
			}
			else if (dataType == 'h') // If the data type is Hex
			{
				for (i = 0; i < numBytes; ++i) // Loop through each byte
				{
					csprintf(hexStr, "%X ", data[i]); // csprintf prints into hexStr a hexadecimal with a space
					UART_PutString(hexStr); // Print hexStr
				}
				UART_PutCRLF();
			}
			else
				goto error;
		}
		else 
			goto error;
		
		continue; // This is so that the error is skipped when everything goes right
		error: // This outputs an invalid format message and continues on to read another line
			UART_CPutString("Invalid format entered. Valid formats are:\r\n\tW [GroupAddress] [MemoryLocation] [h|a] Hex/ASCII\r\n\tR [GroupAddress] [MemoryLocation] [h|a] [NumBytes]\r\n");
	}
}