Ejemplo n.º 1
0
int GSM3SoftSerial::begin(long speed)
{   
	_rx_delay_centering = _rx_delay_intrabit = _rx_delay_stopbit = _tx_delay = 0;
	
	setTX();
	setRX();
	
	for (unsigned i=0; i<sizeof(table)/sizeof(table[0]); ++i)
	{
		long baud = pgm_read_dword(&table[i].baud);
		if (baud == speed)
		{
			_rx_delay_centering = pgm_read_word(&table[i].rx_delay_centering);
			_rx_delay_intrabit = pgm_read_word(&table[i].rx_delay_intrabit);
			_rx_delay_stopbit = pgm_read_word(&table[i].rx_delay_stopbit);
			_tx_delay = pgm_read_word(&table[i].tx_delay);
			break;
		}
	}

	// Set up RX interrupts, but only if we have a valid RX baud rate
	/*
	if (_rx_delay_stopbit)
	{
		pinMode(__RXPIN__, INPUT_PULLUP);
		tunedDelay(_tx_delay); // if we were low this establishes the end
	}
    */
    io_DisableINT();
    io_outpb(CROSSBARBASE + 0x90 + PIN86[__RXPIN__].gpN, 0x08);
	_activeObject = this;
	io_RestoreINT();
}
Ejemplo n.º 2
0
unsigned char SONAR::recvDat(unsigned char desiredSize) {
	debug();
	clearBuf();
	init();	// 201209
	setRX();
	unsigned char datSize=0;
	
#if defined(BOARD_maple) || defined(BOARD_maple_native) || defined(BOARD_maple_mini)
	for(int j=0;datSize<desiredSize && j<15;++j) {
		delay(1);
		unsigned char ibyte=Serial.read();
		
		if(datSize==0 && ibyte!=0x55) continue;
		if(datSize==1 && ibyte!=0xaa) continue;
		_recvBuf[datSize++]=ibyte;
	}
#else//for arduino
	for(int j=0;datSize<desiredSize && j<5000;++j) {
		unsigned char ibyte=Serial.read();
		if(ibyte!=0xff) {
			_recvBuf[datSize++]=ibyte;
		}
	}
#endif

	//SonarPrint.println(Serial.read(), HEX);
	setTX();
	return datSize;
}
Ejemplo n.º 3
0
// try to read a Dynamixel packet
// return true if successful, false otherwise 
uint16_t axReadPacket(uint8_t length){
    setRX();
    usart_timer = 0;
	// wait until the expected number of byte has been read
	while( local_rx_buffer_count < length ){ 
		if(usart_timer > g_usbtoaxregs.s.bUSART_ReceiveTimeout){
		    break;
		}
	}
setTX();
	if (local_rx_buffer_count != length){
		return false;
	}
	
	// TODO check for error in the packet, so that we don't wait if the status packet says that something went wrong... ?
	
	// compute checksum
    uint8_t checksum = 0; // accumulator for checksum
    for(uint8_t i=2; i < length; i++){
        checksum += local_rx_buffer[i];
    }
    
    if((checksum%256) != 255){
        return false; // invalid checksum
    }else{
        return true;
    }
}
Ejemplo n.º 4
0
//
// Constructor
//
SoftwareSerial::SoftwareSerial(uint8_t receivePin, uint8_t transmitPin, bool inverse_logic /* = false */) : 
	_rx_delay_centering(0),
	_rx_delay_intrabit(0),
	_rx_delay_stopbit(0),
	_tx_delay(0),
	_buffer_overflow(false),
	_inverse_logic(inverse_logic)
{
	setTX(transmitPin);
	setRX(receivePin);
}
Ejemplo n.º 5
0
//
// Constructor
//
SoftwareSerial::SoftwareSerial(uint8_t receivePin, uint8_t transmitPin, bool inverse_logic /* = false */) : 
  baud(0),
  _buffer_overflow(false),
  _inverse_logic(inverse_logic)
{
#ifdef DEBUG_SOFTWARESERIAL
    printf("SoftwareSerial rx: pin %d, tx: pin %d\n", receivePin, transmitPin);
#endif
  setTX(transmitPin);
  setRX(receivePin);
}
Ejemplo n.º 6
0
/** send instruction packet */
void AX12::ax12SendPacket (byte _id, byte datalength, byte instruction, byte* data) {
    byte checksum = 0;
    setTX();
    ax12writeB(0xFF);
    ax12writeB(0xFF);
    checksum += ax12writeB(_id);
    checksum += ax12writeB(datalength + 2);
    checksum += ax12writeB(instruction);
    for (byte f=0; f<datalength; f++) {     // data = parámetros
      checksum += ax12writeB(data[f]);
    }
    // checksum =
    ax12writeB(~checksum);
    setRX();
}