コード例 #1
0
/* Watchdog Timer interrupt service routine.  The function prototype
 *  tells the compiler that this will service the Watchdog Timer, and
 *  then the function follows.
 *    */
void run()
{
  //Transmit process
  Setup_TX(ADXL_345);
  TransmitOne(0x32);                      // Request Data from ADXL345
  while (UCB0CTL1 & UCTXSTP);             // Ensure stop condition got sent

  //Receive process
  Setup_RX(ADXL_345);
  Receive();
  while (UCB0CTL1 & UCTXSTP);             // Ensure stop condition got sent

  acc[0] = ((((int)RxBuffer[1]) << 8) | RxBuffer[0]) << 6;
  acc[1] = ((((int)RxBuffer[3]) << 8) | RxBuffer[2]) << 6;
  acc[2] = ((((int)RxBuffer[5]) << 8) | RxBuffer[4]) << 6;
    
  // now You have XYZ axis reading in x1,x2,x3 variable....Bingo... you can play with it as you like....
  // Below if sense x and y angle and Red led is on if its more then 45 or less then -45...
  // you can put your own condition here...

  if ((acc[0] > 0x2000) || (acc[1] > 0x2000) || (acc[0] < -0x2000) || (acc[1] < -0x2000)) {
    P1OUT |= BIT0; // red led on
  }
  else {
    P1OUT &= ~BIT0; // red led off
  }

  Setup_UART();
  /* UARTSendArray("sample\n", 7); */
  /* UARTSendInt(acc[0]); */
  /* UARTSendInt(acc[1]); */
  /* UARTSendInt(acc[2]); */
  hmm();
}
コード例 #2
0
int main(void)
{
  // LED
  P1DIR |= BIT0;
  /* P1OUT |= BIT0; */

  // UART
  BCSCTL1 = CALBC1_1MHZ; // Set DCO to 1MHz
  DCOCTL = CALDCO_1MHZ; // Set DCO to 1MHz

  // Configure hardware UART
  P1SEL |= BIT1 + BIT2 ; // P1.1 = RXD, P1.2=TXD
  P1SEL2 |= BIT1 + BIT2 ; // P1.1 = RXD, P1.2=TXD
    
  Setup_UART();
  UARTSendArray("Hello\n", 6);
  __delay_cycles(1000);

  // ADXL345
  P1SEL  |= BIT6 + BIT7;                     // Assign I2C pins to USCI_B0
  P1SEL2 |= BIT6 + BIT7;                     // Assign I2C pins to USCI_B0

  // Init sequence for ADXL345
  //Transmit process
  Setup_TX(ADXL_345);
  Transmit(0x2D,0x00);                    // STUCK
  while (UCB0CTL1 & UCTXSTP);             // Ensure stop condition got sent

  //Transmit process
  Setup_TX(ADXL_345);
  Transmit(0x2D,0x10);
  while (UCB0CTL1 & UCTXSTP);             // Ensure stop condition got sent

  //Transmit process
  Setup_TX(ADXL_345);
  Transmit(0x2D,0x08);
  while (UCB0CTL1 & UCTXSTP);             // Ensure stop condition got sent
  

  /* Set watchdog timer interval to 1000ms (requires external crystal to work) */
  WDTCTL = WDT_ADLY_1_9;

  /* "Interrupt enable 1" for the Watchdog Timer interrupt */
  IE1 |= WDTIE;

  /* Go into low power mode 3, general interrupts enabled */
  __bis_SR_register( LPM3_bits + GIE );

  /* Do nothing...forever */
  for( ; ; ) { }
}
コード例 #3
0
ファイル: btdfu.c プロジェクト: huangjionghui/8803-project
int set_bt_dfu(void)
{
	int ret = -1;
	U16 tx_size  = 1000;
	U16 cmd_type = 1;
	U32 bt_dfu_file_size=0;
	U32	org_baudrate = SERIAL_BAUDRATE_OLD;
	U32 high_speed_baudrate = SERIAL_BAUDRATE_NEW;
	
	COMPortString = (U8*)SERIAL_BT_NAME;
	
	/*设定模組使用协议
		CmdType,处理不同协议用的. 
		COW 协议设为 0,
		FIH 协议设为 1,
		FLC 协议设为 2,
		GOC 协议设为 3,
		DEG 协议设为 4
	*/
	if (!SetDFUCmd(cmd_type))
	{
		DLOGD("Command Set Set Fail\n");
		ret = -1;
		goto fail;
	}
	CurrCmdType = cmd_type;

	//设定程式需使用到的 buffer
	memset(UARTRawBuf, 0, 256);
	setup_DataBuffer(UARTRawBuf, BCSPRxBuf, BCSPTxBuf, BCSPAckBuf);
	
	
	//设定 UART
	if (Setup_UART(org_baudrate, curDFU.UARTRawBuffer) < 0)
	{
		DLOGD("Setup_UART err\n");
		goto fail;
	}
	//Setup_Timer();
	
	//打开DFU升级文件
	dfu_fd = open(DUF_FILE_NAME, O_RDONLY, 0777);
	if (dfu_fd <= 0){
		DLOGD("open dfu file err!\n");
		ret = -2;
		goto fail;
	}
	
	bt_dfu_file_size = get_file_size(DUF_FILE_NAME);
	if (!bt_dfu_file_size){
		DLOGD("get dfu file size is zero\n");
		ret = -3;
		goto fail;
	}
	DLOGD("bt dfu file size is :%d", bt_dfu_file_size);
	
	//DFU 功能初始化动作
	init_DFU(bt_dfu_file_size, org_baudrate, high_speed_baudrate, tx_size, cmd_type);
	
	//OSTimeDly(500);
	//开始 DFU 更新,直到更新完成或更新错误时結束
	DoDFU();
	DLOGD("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
	DLOGD("----->load:%d/100, fileSizeDownloaded:%d,fileSize:%d", 
			curDFU.fileSizeDownloaded*100/(curDFU.fileSize-16), curDFU.fileSizeDownloaded, curDFU.fileSize);
	DLOGD("===================%s %s===================", __TIME__, __DATE__);
	if (curDFU.ErrCode)
	{
		unsigned long written = 0;
		U8 i=0;
		DLOGD("\nError occurs during DFU Progressing\r\n");
		DLOGD("\tCurrent Stage is %u\r\n", curDFU.curStage);
		DLOGD("\tCurrent EVENT is %u\r\n", curDFU.curEvent);
		DLOGD("\tError Code is 0x%x\r\n", curDFU.ErrCode);

		if (curDFU.curEvent == UPGRADE_EVENT_ERROR)
		{
			DLOGD("\t\tAdvErrCode is %u\r\n", curDFU.AdvErrCode);
		}
		ret = -4;
		goto fail;
	}
	else
	{
		DLOGD("\nDevice Upgrade Completed !!, total time:%d sec\r\n\r\n\r\n", 
				CountTimeInterval(StartDFUTime, GetTimeReg())/1000);
		ret = 1;
	}
fail:
	DLOGD("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");

	serial_thread_status = 0;
	bt_serial_close(serial_fd);
	OSTimeDly(1000);
	close(dfu_fd);
	DLOGD("ret =%d\n", ret);
	return ret;
}