コード例 #1
0
ファイル: ds18b20.c プロジェクト: Dearn/SW2
short ds18b20ReadTempNoRom(void)
{
	owStrongPullupOff();
	if(owPresence())
	{
		unsigned char tempL;
		unsigned char tempH;
		volatile unsigned char Th;
		volatile unsigned char Tl;
		volatile unsigned char res1;
		volatile unsigned char res2;
		volatile unsigned char crc;
		owWrite(ONE_WIRE_CMD_SKIP_ROM);
		owWrite(ONE_WIRE_CMD_READ_SCRATCHPAD);
		tempL = owRead();
		tempH = owRead();
		Th = owRead();
		Tl = owRead();
		res1 = owRead();
		res2 = owRead();
		COUNT_REMAIN = owRead();
		COUNT_PER = owRead();
		crc = owRead();
		owPresence();
//		COUNT_REMAIN = COUNT_REMAIN/2;
//		COUNT_PER = (COUNT_PER-COUNT_REMAIN)/COUNT_PER);
//		LCDPutunsigned char(0x30+((COUNT_PER-COUNT_REMAIN)/COUNT_PER)*10000, 40, 10, LARGE, BLACK, YELLOW);

		{short temperature = ( (unsigned short)tempH << 8) | tempL;
		return(temperature);
		}
	}
	return(0x7FFF);
}
コード例 #2
0
ファイル: ds18b20.c プロジェクト: Dearn/SW2
void ds18b20ConvertT(void)
{
	if(owPresence()==OK)
	{
		owWrite(ONE_WIRE_CMD_SKIP_ROM);
		owWrite(ONE_WIRE_CMD_CONVERT_T);
		owStrongPullupOn();
	}
}
コード例 #3
0
ファイル: memutil.c プロジェクト: devenfan/sparrow-hawk
/**
 * Write a block of data with the provided MemoryBank.
 *
 * bank    MemoryBank to write block to
 * portnum port number for the device.
 * SNum    serial number for the device.
 * addr    address to start the write.
 * data    data to write in a byte array
 * length  length of the data to be written
 *
 * @return 'true' if the write worked.
 */
SMALLINT bankWriteBlock (SMALLINT bank, int portnum, uchar SNum[8], int addr,
                         uchar *data, int length)
{
   if(!owWrite(bank,portnum,SNum,addr,data,length))
      return FALSE;

   printf("\nWrote block length %d at addr %d\n",length,addr);

   return TRUE;
}
コード例 #4
0
void memWriteProcess()
{
  uint8_t memId = p.data[0];
  uint8_t writeLen;
  uint32_t memAddr;
  uint8_t status;

  memcpy(&memAddr, &p.data[1], 4);
  writeLen = p.size - 5;

  DEBUG("Packet is MEM WRITE\n");
  p.header = CRTP_HEADER(CRTP_PORT_MEM, WRITE_CH);
  // Dont' touch the first 5 bytes, they will be the same.
  if (memId == EEPROM_ID)
  {
    if (memAddr + writeLen <= EEPROM_SIZE &&
        eepromWriteBuffer(&p.data[5], memAddr, writeLen))
      status = 0;
    else
      status = EIO;
  }
  else
  {
    memId = memId - NBR_EEPROM;
    if (memAddr + writeLen <= OW_MAX_SIZE &&
        owWrite(memId, memAddr, writeLen, &p.data[5]))
      status = 0;
    else
      status = EIO;
  }

  p.data[5] = status;
  p.size = 6;

  crtpSendPacket(&p);
}
コード例 #5
0
ファイル: ow_syslink.c プロジェクト: FreeRTOSHAL/copterOS
bool owTest()
{
  uint8_t nOwMem = 0;
  uint8_t nOwIter = 0;
  OwSerialNum sn;

  if (owScan(&nOwMem))
  {
    DEBUG_PRINT("Found %d.\n", nOwMem);
  }
  else
  {
    DEBUG_PRINT("Scan [FAILED].\n");
  }

  for (nOwIter = 0; nOwIter < nOwMem; nOwIter++)
  {
    if (owGetinfo(nOwIter, &sn))
    {
      DEBUG_PRINT("Serial 0x%X %X %X %X %X %X %X %X.\n",
                  sn.type, sn.id[0], sn.id[1], sn.id[2],
                  sn.id[3], sn.id[4], sn.id[5], sn.crc);
    }
    else
    {
      DEBUG_PRINT("Mem:%d Getinfo [FAILED].\n", nOwIter);
    }
  }

#ifdef OW_READ_TEST
  {
    static uint8_t testbuf[129];

    if (owRead(0, 0, OW_MAX_SIZE, testbuf))
    {
      for (nOwIter = 0; nOwIter < OW_MAX_SIZE; nOwIter++)
      {
        consolePrintf("%X ", testbuf[nOwIter]);
        testbuf[nOwIter] = nOwIter;
      }
      consolePrintf("\n");
    }
  }
#endif
#ifdef OW_WRITE_TEST
  if (owWrite(0, 0, sizeof(bqData), bqData))
  {
    DEBUG_PRINT("Write [OK].\n");
  }
  else
  {
    DEBUG_PRINT("Write [FAIL].\n");
  }
//  if (owWrite(1, 0, sizeof(dummyData2), dummyData2))
//  {
//    DEBUG_PRINT("Write [OK].\n");
//  }
//  else
//  {
//    DEBUG_PRINT("Write [FAIL].\n");
//  }
#endif

  return true;
}
コード例 #6
0
static bool expbrdScan(void)
{
  uint8_t i = 0;
  bool status = false;
#if 1
  if (owScan(&nBoards))
  {
    DEBUG_PRINT("Found %d memories.\n", nBoards);
  }
  else
  {
    DEBUG_PRINT("Scan [FAILED].\n");
  }


#if 0
  expbrdData[0].header = EXPBRD_ID;
  expbrdData[0].vid    = EXPBRD_VID_BITCRAZE;
  expbrdData[0].pid    = EXPBRD_PID_LEDRING;
  expbrdData[0].crc = crcSlow( (uint8_t *)&expbrdData[0], sizeof(ExpbrdData) - 1);

  status = owWrite(0, EXPBRD_OW_ADDR, sizeof(ExpbrdData), (uint8_t *)&expbrdData[0]);

  if( status == true )
  {
	  DEBUG_PRINT("owWrite LED Ring OK\n");
  }
  else
  {
	  DEBUG_PRINT("owWrite LED Ring Fail\n");
  }
#endif



  for (i = 0; i < nBoards; i++)
  {
    if (owRead(i, EXPBRD_OW_ADDR, sizeof(ExpbrdData), (uint8_t *)&expbrdData[i]))
    {
      if (expbrdIsValid(&expbrdData[i]))
      {
        DEBUG_PRINT("Info board %i:\n", i);
        expbrdPrintData(&expbrdData[i]);
        status = true;
      }
    }
    else
    {
      DEBUG_PRINT("Reading board nr:%d [FAILED].\n", i);
    }
  }
#endif
  /*
  nBoards = 1;
  expbrdData[0].header = EXPBRD_ID;
  expbrdData[0].vid    = EXPBRD_VID_BITCRAZE;
  expbrdData[0].pid    = EXPBRD_PID_LEDRING;
  expbrdData[0].crc = crcSlow( (uint8_t *)&expbrdData[0], sizeof(ExpbrdData) - 1);
  */

  owScan(&nBoards);

  return status;
}