Esempio n. 1
0
/*
 * main.c
 */
int main(void) {
	WDTCTL = WDTPW | WDTHOLD;		// Stop watchdog timer

	// Set up master clk
	DCOCTL |= DCO2 | DCO1 | DCO0;
	BCSCTL1 |= RSEL3 | RSEL2 | RSEL1 | RSEL0;

	// Initilize communications
	InitUART();
	InitSPI();

	// Enable interrupts
	__enable_interrupt();
	IE2 = UCA0TXIE | UCA0RXIE | UCB0TXIE | UCB0RXIE;

	//while(!(IFG2 & UCA0RXIFG));

	//uint8_t echo = UCA0RXBUF;

	while(1) {
		//UARTTransmit(echo);
		//while(!(IFG2 & UCA0RXIFG));
		//echo = UCA0RXBUF;
	}

	return 0;
}
Esempio n. 2
0
void main(void)
{
    /* Configure the oscillator for the device */
    ConfigureOscillator();

    /* Initialize I/O and Peripherals for application */
    InitApp();
    InitSPI();
    InitInterrupts();

    LCD_Init();

    RF_ConfigReceiver();
    LCD_WriteFirstLine("NRF Initialized");
//    LCD_Write();

    
    while(1)
    {
        if(RF_ReceiveFlag == 1){
            RF_ResetReceiver();
            if(RF_ReceiveBuffer[0] == 0x01){
                ToggleLED_B7();
                LCD_WriteFirstLine("Receive Action:");
                LCD_WriteSecondLine("L-Button Pressed");
            }

            else if(RF_ReceiveBuffer[0] == 0x02){
                ToggleLED_B7();
                LCD_WriteFirstLine("Receive Action:");
                LCD_WriteSecondLine("R-Button Pressed");
            }
        }
    }
}
Esempio n. 3
0
/**
 * NtrxInit:
 *
 * NtrxInit() initializes the entire necessary hardware parts of
 * the nanoNET TRX chip. It also initializes all necessary software data.
 *
 * Returns: TRUE if everything O.K. else FALSE
 */
MyBoolT NtrxInit(void)
{
  settingVal.bw = NA_80MHz;
  //settingVal.bw = NA_22MHz;
  settingVal.sd = NA_1us;
  settingVal.sr = NA_1M_S;
  settingVal.fdma= FALSE;
  settingVal.fixnmap=NA_FIX_MODE;
  settingVal.rangingConst=122.492363;

  NTRXCheckTable();
  /* init SPI HW&SW */
  nanorest_init();
  InitSPI();

  NanoReset();
  hwdelay(500);		//等待足够长的时间,使nano运行稳定
  /*
  * configure SPI output of chip MSB first / push pull
  */
  SetupSPI ();
  /* initialize shadow registers */
  NTRXInitShadowRegister ();
  hwdelay(100);
   //!! Some short delay seems necessary here??
  /* check connection and firmware version and revision */
  if(FALSE == NTRXCheckVerRev()){
  	return FALSE;
  }
  NTRXSetupTRxMode (settingVal.bw, settingVal.sd, settingVal.sr);
  nanoint_init();
  ntrxRun = FALSE;
  return TRUE;
}
Esempio n. 4
0
unsigned char TestFlash(void)
{

    // Stat led
    s_pPio->PIO_PER   = BIT31;
    s_pPio->PIO_OER   = BIT31;    // Configure PA11 as output
    s_pPio->PIO_SODR  = BIT31;    // Set PA11 to HIGH

    char i;

    // Test led and flash memory
    InitSPI();

    // Write WriteBuffer
    for(i=0; i<10; i++) 
    {
      ByteToBuffer(WriteBuffer[i], i);
    }
    WriteBufferToMainMemory(0);

    // Read ReadBuffer
    FlashReadArray(0, ReadBuffer, 10);

    // check for Correct Read
    for(i=0; i<10; i++) 
    {

      if(WriteBuffer[i]!=ReadBuffer[i]) 
      {
        return 0;
      }
    }

    return 1;
}
Esempio n. 5
0
static void initHardware(void)
{
	Chip_SetupXtalClocking();
	Chip_SYSCTL_SetFLASHAccess(FLASHTIM_100MHZ_CPU);
    SystemCoreClockUpdate();


/*====================[PARA MODULO RF]====================*/
	Chip_GPIO_WriteDirBit(LPC_GPIO, CE_PIN, 1); //Puerto CE
	Chip_GPIO_SetPinOutLow(LPC_GPIO, CE_PIN); //Puerto CE
	InitSPI ();

	begin();
	setPALevel(RF24_PA_LOW);
	openWritingPipe(&addresses2[0]);
	openReadingPipe(1,&addresses1[0]);	//1Node: Transmite paquetes el tx por este pide (addres)

	startListening();

/*========================================================*/



//    Board_Init();

//    Board_LED_Set(0, false);

    SysTick_Config(SystemCoreClock/1000);		//1000 ticks por segundo

	InitPWM_motores(0);			//Función inicialización modulo PWM
	InitPWM_motores(1);			//Función inicialización modulo PWM
	InitPWM_motores(2);			//Función inicialización modulo PWM
	InitPWM_motores(3);			//Función inicialización modulo PWM
	InitPWM0();
	InitGPIO(0);			//Llamo función para inicializar GPIO
	InitGPIO(1);			//Llamo función para inicializar GPIO
	InitGPIO(2);			//Llamo función para inicializar GPIO
	InitGPIO(3);			//Llamo función para inicializar GPIO
	Stop_and_Default(0);	//Condiciones iniciales
	Stop_and_Default(1);	//Condiciones iniciales
	Stop_and_Default(2);	//Condiciones iniciales
	Stop_and_Default(3);	//Condiciones iniciales


    P2_6ER = 1;    P2_7ER = 1;    P2_8ER = 1;

    P2_6EF = 1;    P2_7EF = 1;    P2_8EF = 1;



    P0_15ER = 1;    P0_16ER = 1;    P2_9ER = 1;

    P0_15EF = 1;    P0_16EF = 1;    P2_9EF = 1;

    NVIC_SetPriority(EINT3_IRQn,1);			//Le pongo la mayor prioridad a la interrupcion
    NVIC_EnableIRQ(EINT3_IRQn);


}
Esempio n. 6
0
File: SD.c Progetto: ankva/sdfatlite
UINT8 SD_Init(void) 
{
    _SD_PRESENT=_IN;
    
    /* Check for SD */
    if(SD_PRESENT)
        return(NO_SD_CARD);
    
    /* Initialize SPI Module */
    InitSPI();

    /* Start SD card Init */
    SPI_SS=ENABLE;
    SD_CLKDelay(10);            // Send 80 clocks 
    SPI_SS=DISABLE;
  
    gu8SD_Argument.lword=0;
    SD_CLKDelay(8);  
    
    /* IDLE Command */
    
    SPI_SS=ENABLE;
    if(SD_SendCommand(SD_CMD0|0x40,SD_IDLE))
    {
        SPI_SS=DISABLE;
        return(INIT_FAILS);      
    }
    SPI_SS=DISABLE;
    
    (void)ReadSPIByte();  // Dummy SPI cycle
    
    /*  Initialize SD Command */
    SPI_SS=ENABLE;
    while(SD_SendCommand(SD_CMD1|0x40,SD_OK)) ;
    SPI_SS=DISABLE;
    
    (void)ReadSPIByte();  // Dummy SPI cycle

    /*  Block Length */
    SPI_SS=ENABLE;
      
    gu8SD_Argument.lword=SD_BLOCK_SIZE;
    if(SD_SendCommand(SD_CMD16|0x40,SD_OK))
    {
        SPI_SS=DISABLE;
        return(INIT_FAILS);      
    }
    
    SPI_SS=DISABLE;
    
    //HighSpeedSPI();

    WriteSPIByte(0x00);
    WriteSPIByte(0x00);
    return(OK);
}
Esempio n. 7
0
//Initialize system
void Init()
{
	unsigned int		i;

	IFG1 &= ~OFIFG;

	// Stop watchdog timer to prevent time out reset
    WDTCTL = WDTPW + WDTHOLD;

	//Adjust DCO frequency
//    //DCOCTL	= DCO0 + DOC1 +DOC2;
//	DCOCTL	= 0x80;
//	BCSCTL1	= XT2OFF + RSEL0 + RSEL1 + RSEL2;
//	BCSCTL2	= 0;

	//调整DCO的频率
	DCOCTL = 0xE0;

	//切换MCLK到外部高速晶振(需要检测是否起振)
	//BCSCTL1 &= ~XT2OFF;		//启动高速晶振
	BCSCTL1 = RSEL0 + RSEL1 + RSEL2;

	do
	{
		//清除振荡器失效标志位,再延迟检查
		IFG1 &= ~OFIFG;
		for (i = 0; i < 1000; i++)
		{
			__no_operation();
		}
	} while (IFG1 & OFIFG);

	//使用XT2, SMCLK = MCLK = 8MHz
	BCSCTL2 = SELM1 + SELS;

	//允许外部振荡器失效后,重启系统
	IE1 |= OFIE;


	InitPort();

	InitUART();

	InitADC();

	InitSPI();

	InitRF();

	InitSensors();

	InitTimer();


	ShutdownModule();
}
Esempio n. 8
0
/* Description: Initialises the teensy, SPI module, transceiver and ADC module.
 */
void Init()
{
    // Set inputs.
    DDRD |= SHIFT(DDD1) | SHIFT(NIRQ);
    PORTD |= SHIFT(PORTD1) | SHIFT(NIRQ);

    InitADC();

    InitSPI();

    InitAlpha();
}
Esempio n. 9
0
void Setup(void)
{
    //pin des LEDs en sortie
    _TRISA0 = 0;
    _TRISA1 = 0;

    /*//Si on a un interrupteur sur la pin RB5 (par exemple), on la met en entrée
    _TRISB5 = 1;
    //Et on active la pullup qui va bien (registres CNPU1 et CNPU2)
    _CN27PUE = 1;
    */

    //On ouvre le module SPI
    InitSPI();

}
Esempio n. 10
0
int main(int argc, char** argv)
{

    //Initializations
    InitCLK();
    InitGPIO();
    InitDAC();
    InitSPI();
    InitTimer0();
    InitWatchdog();

    //Setup interrupts
    PEIE = 1;
    GIE = 1;

    SPI_CS = CS_IDLE; //must be changed!


    SSPCON1bits.SSPEN=0;  // Disable SPI Port
    //PORTCbits.RC5 = 0;    //Set MOSI low
    //PORTCbits.RC3 = 0;    //Set SCK low
    PORTCbits.PORTC = LATCbits.LATC & 0xD7; //set MOSI and SCK low

    while(1)
    {
        SPI_CS = CS_IDLE; //hands off mode for testing the launcher

        //Check if beacon has been launched
        CheckDisconnect(); //DONE+TESTED

        if(playbackFlag&&!MEM_ACCESS)
        {
            PlaybackMode();
            playbackFlag = 0;
        }

        //Transmit message
        if(transmitFlag) //DONE+TESTED
            TransmitMode(); //DONE+TESTED

        //Go back to sleep, wait for interrupts
        Hibernate();
    }

    return (EXIT_SUCCESS);
}
Esempio n. 11
0
void main()
{
    InitUart();                 //initial UART
    InitSPI();                  //initial SPI
    IE2 |= ESPI;
    EA = 1;

    while (1)
    {
#ifdef MASTER                   //for master (receive UART data from PC and send it to slave, in the meantime
                                //            receive SPI data from slave and send it to PC)
        ACC = RecvUart();
        SPISS = 0;              //pull low slave SS
        SPDAT = ACC;            //trigger SPI send
#endif
    }
}
Esempio n. 12
0
//----------------------------
void main()      
{ 
  char ru;
  InitSystemClock();
  InitPortsIO();   
  InitSPI();
  //InitTimers();
  //EnableInterrupts(); 
  InitLCD();
  DrawFillRectangle(1,1,130,130,0x000000);//Background
  ru=PIND;
  //DrawText(1,1,"Hello /@",1);
  for (char i=1;i<=255;i+=2) {
   DrawFillRectangle(1,i/2,130,1,i);   
  };
  while (1)   
  {   
    
  }   
} 
Esempio n. 13
0
/****************************************************************************
 Function
     InitJSRcommand

 Parameters
     uint8_t : the priorty of this service

 Returns
     bool, false if error in initialization, true otherwise

 Description
     Saves away the priority, and does any 
     other required initialization for this service
 Notes

 Author
     J. Edward Carryer, 01/16/12, 10:00
****************************************************************************/
bool InitJSRcommand ( uint8_t Priority )
{
   ES_Event ThisEvent;

   MyPriority = Priority;
  
   // post the initial transition event
   DDRS |= BIT7HI; // To control SS line manually
   RED_DARK_ADDRESS &= ~RED_DARK_PIN; // Set pin as input
   RED_DARK_PORT &= ~RED_DARK_PIN; //Set button low
   InitSPI();
   readFrom = 4;// Looking for the 4th command from JSR
   InitVariables();
   QueryCommand =  STATUS_QUERY;
   ES_Timer_InitTimer(JSRtimer, 3); // Start JSRtimer for 2ms.
 
   ThisEvent.EventType = ES_INIT;
   if (ES_PostToService( MyPriority, ThisEvent) == true)
      return true;
   else
      return false;
}
BOOL setMode(BYTE pin,BYTE mode){
	println_I("Setting Mode: ");printMode(mode,INFO_PRINT);print_I(" on: ");p_int_I(pin);
	BYTE currentMode = GetChannelMode(pin);
	ClearCounter(pin);
	StopSPI(pin);
	clearPPM(pin);
	print_I(" \tHardware Cleared");
	switch (mode){
	case IS_SERVO:
		if(((pin < 12) && (isRegulated_0() == 0)) || ((pin >= 12) && (isRegulated_1()== 0))   ){
			print_I("|Mode is now servo");
			break;
		}else{
			if(getBrownOutDetect()){
				print_I(" Servo Mode could not be set, voltage invalid");
				return FALSE;
			}else{
				print_I(" Servo Mode set|");
				break;
			}
		}
		break;
	case IS_SPI_MOSI:
	case IS_SPI_MISO:
	case IS_SPI_SCK:
		if( pinHasFunction(pin, mode) != FALSE){
			print_I("|Mode is now SPI");
			InitSPI();
			break;
		}else{
			return FALSE;
		}
		break;
	case IS_COUNTER_INPUT_INT:
	case IS_COUNTER_INPUT_DIR:
	case IS_COUNTER_INPUT_HOME:
		if(pinHasFunction(pin, mode) != FALSE){
			print_I("|Mode is now Counter Input");
			StartCounterInput(pin);
			break;
		}else{
			print_I(", Counter Input not availible");
			return FALSE;
		}
		break;
	case IS_COUNTER_OUTPUT_INT:
	case IS_COUNTER_OUTPUT_DIR:
	case IS_COUNTER_OUTPUT_HOME:
		if(pinHasFunction(pin, mode) != FALSE){
			print_I("|Mode is now Counter Output");
			StartCounterOutput(pin);
			break;
		}else{
			print_I(", Counter Output not availible");
			return FALSE;
		}
		break;
	case IS_PPM_IN:
		println_I("Setting up PPM...");
		startPPM(pin);
		break;
	}
	print_I(" \tMode set");
	return TRUE;
}
Esempio n. 15
0
uint8_t GetByteSPI(uint8_t b){
	InitSPI();
	putcSPI2(b);	// Start sending
	return getcSPI2();
}
Esempio n. 16
0
/***********************************************************************
 *
 *    SD_Init
 *
 *  Description: Configures the SPI2 module and the File system to handle
 *                 an SD Card.
 *
 *  Returns:     OK if SPI configured, SD card is present, CMD0 true, 
 *                  SD card initialised, block length set to 512, 
 *                  SPI clock set to 4MHz.
 *               NO_SD_CARD if no SD card is present.
 *               INIT_FAILS if CMD0 (idle) fails, block length set fails.
 *               
 *               .
 *
 *************************************************************************/
UINT8 SD_Init(void) {

	UINT8 Count;
	UINT8 res;
	UINT8 CRC7_BYTE;
	UINT8 j;
	UINT8 i = 0;

	/* Configure the SD Card inserted detection pin */_SD_PRESENT = _IN; // Configure the data direction as IN.
	SD_PRESENT_PU = 1; // Enable Internal Pull-UP Resistor

	/* Initialise SPI Module */InitSPI(); // SS high, 375kHz clock.

	/* Delay SD card requires a delay of at least 1mSec after power up */
	for (j = 0; j < 200; j++) {
		for (Count = 0; Count < 255; Count++) {
			i += 1;
		}
	}

	/* Check for SD */
	if (SD_PRESENT) // Pin is low when SD Card present
//        return(NO_SD_CARD);
		return (0x11);

	/*** Start SD card Init ***/
	/* Minimum of 74 dummy clock cycles with MOSI high & SS enabled (low) */
//    SPI_SS = ENABLE;           // Enable SS
//    SD_CLKDelay(10);            // Send 80 clocks
//    SPI_SS_Disable_Delay(); 
//    SPI_SS = DISABLE;
	SD_CLKDelay(10); // Send 80 clocks with SS disabled
	SPI_SS_Disable_Delay();

	/* CMD0 - GO_IDLE_STATE
	 Reset the sd card & place it in SPI mode.
	 CRC must be valid.
	 Valid reset command is 0x40, 0x00, 0x00, 0x00, 0x00, 0x95.
	 Correct response is R1 (1 byte) = SD_IDLE (0x01).  
	 Note that the command frame starts with 
	 bits 47:46=0:1 (start & transmission bits) 
	 so the CMD byte has b6 set. */

	SPI_SS = ENABLE;
	gu8SD_Argument.lword = 0; // CMD0 argument is 0x00, 0x00, 0x00, 0x00.
	if (SD_SendCommand(SD_CMD0 | 0x40, SD_IDLE)) // returns OK (0x00) if OK
			{
		SPI_SS = DISABLE;
//        return(INIT_FAILS);
		return (0x12);
	}
	/* Card is in Idle State */
	SPI_SS_Disable_Delay();
	SPI_SS = DISABLE;

	SD_CLKDelay(1); // 8 dummy clocks

	/* Check if card is Ver2 compliant.
	 Send a SEND_IF_COND (CMD8) with supply voltage (VHS) set to 2.7-3.6volts.
	 Argument will be 0x000001AA and CRC7 + end bit 0x87.
	 CMD8 response is R7 (5 bytes - R1 + argument). */

	SPI_SS = ENABLE;
	gu8SD_Argument.lword = 0x000001AA;
	CRC7_BYTE = 0x87;
	if (SD_SendCommandR7(SD_CMD8, CRC7_BYTE)) {
		SPI_SS = DISABLE;
//        return(INIT_FAILS);
		return (0x13);
	}
	/* Card is version 2 compliant */
	SPI_SS_Disable_Delay();
	SPI_SS = DISABLE;

	SD_CLKDelay(1); // 8 dummy clocks

	/* Read the Operation Conditions Register OCR & check for correct voltage range.
	 Valid voltage range of 2.7-3.6 volts is indicated by 
	 gu8SD_Response[2:3] = 0xFF:0x80. Ref Table 5-1 P92.
	 Send READ_OCR CMD58.
	 CMD58 response R3 (5bytes - R1 + OCR). */SPI_SS = ENABLE;
	gu8SD_Argument.lword = 0x00000000;
	CRC7_BYTE = 0xFD;
	if (SD_SendCommandR3(SD_CMD58, SD_IDLE, CRC7_BYTE)) // Correct R1 is SD_IDLE (0x01)
			{
		SPI_SS = DISABLE;
//        return(INIT_FAILS);
		return (0x14);
	}
	/* Valid response received */
	SPI_SS_Disable_Delay();
	SPI_SS = DISABLE;
	SD_CLKDelay(1); // 8 dummy clocks
	/* Check for correct voltage range */
	if ((gu8SD_Response[2] != 0xFF) && (gu8SD_Response[3] != 0x80)) {
//      return(INIT_FAILS);
		return (0x15);
	}

	/* Initialise Card */
	/* Send continuous SD_SEND_OP_COND (ACMD41) until R1 b0 clears. */

	j = 0; // Clear loop counter
	do {
		j++;
		/* The next command is an application-specific command */
		do { // Wait for a successful CMD55
			/* The next command is an application-specific command */
			SPI_SS = ENABLE; // Enable SS
			gu8SD_Argument.lword = 0x00000000;
//        res = SD_SendCommand(SD_CMD55|0x40,0x80);  // returns OK (0x00) if  
			res = SD_SendCommand(SD_CMD55 | 0x40, SD_IDLE); // returns OK (0x00) if
															//  any valid response received
			SPI_SS_Disable_Delay();
			SPI_SS = DISABLE;
			SD_CLKDelay(1); // 8 dummy clocks
		} while (res);

		/* Send SD_SEND_OP_COND (ACMD41) */
		do {

			SPI_SS = ENABLE; // Enable SS
			/* High Capacity Support (HCS - argument b30) is set if host supports
			 SDHC or SDXC, wgich it does not in this case. */
//        gu8SD_Argument.lword = 0x40000000;            // HCS set
			gu8SD_Argument.lword = 0x00000000; // HCS clear
			res = SD_SendCommand(SD_CMD41 | 0x40, 0x80); // returns OK (0x00) if
//        res = SD_SendCommand(SD_CMD41|0x40,SD_OK);     // returns OK (0x00) if
					//  any valid response received
			SPI_SS_Disable_Delay();
			SPI_SS = DISABLE;
			SD_CLKDelay(1); // 8 dummy clocks
		} while (res);
	} while ((gu8SD_Response[0] != SD_OK) && (j < SD_IDLE_WAIT_MAX));

	/* Assume we're OK if we didn't hit the timeout */
	if (j >= SD_IDLE_WAIT_MAX)
//       return(INIT_FAILS);
		return (0x16);

	/* Read the Operation Conditions Register OCR & 
	 check the Card Power Up Status bit b31 and Card Capacity Status (CCS) b30. 
	 b31 & b30 of the OCR which is gu8SD_Response[1] b6. 
	 Power Up Status Bit will be 1 when the card is finished powering up.
	 CCS is 0 for a SDSC. Ref Table 5-1 P92.
	 Send READ_OCR CMD58.
	 CMD58 response R3 (5bytes - R1 + OCR). */SPI_SS = ENABLE;
	gu8SD_Argument.lword = 0x00000000;
	CRC7_BYTE = 0xFD;
	if (SD_SendCommandR3(SD_CMD58, SD_OK, CRC7_BYTE)) // Correct R1 response is SD_OK (0x00)
			{
		SPI_SS = DISABLE;
//        return(INIT_FAILS);
		return (0x17);
	}
	/* Valid response received */
	SPI_SS_Disable_Delay();
	SPI_SS = DISABLE;
	SD_CLKDelay(1); // 8 dummy clocks

	/* Check Power Up Status */
	if ((gu8SD_Response[1] & 0x80) == 0x00)
		return (0x19); // return Power Up not finished.

	/* Check CCS  */
	if (gu8SD_Response[1] & 0x40)
		return (0x1A); // return Card is not SDSC.

	/*  Set the Block Length to 512 bytes */SPI_SS = ENABLE;

	gu8SD_Argument.lword = SD_BLOCK_SIZE; // 512 bytes
	if (SD_SendCommand(SD_CMD16 | 0x40, SD_OK)) {
		SPI_SS = DISABLE;
//        return(INIT_FAILS);
		return (0x18);
	}

	SPI_SS_Disable_Delay();
	SPI_SS = DISABLE;
	SD_CLKDelay(1); // 8 dummy clocks

//    WriteSPIByte(0x00);
//    WriteSPIByte(0x00);

	/* Read the Card-Specific Data register (CSD) to gu8SD_CSD[16] */
	if (SD_Read_CSD()) {
		return (0x1B); // error 11. CSD read fail
	}

	HighSpeedSPI();

	return (OK);
}
BYTE GetByteSPI(BYTE b){
	InitSPI();
	putcSPI2(b);	// Start sending
	return getcSPI2();
}