Пример #1
0
/** Initialise the Serial port at a specific Baud Rate
*
* This function initialises the serial port as well as setting up the input
* pin attached to the Serial port. The set up accepts portname as the Windows
* comport name : ie "COM1" or in Linux "/dev/ttyUSB0". The Baudrate is
* optional. On some platforms like the Attiny85 with softuart it's fixed
* to a precompiled vale and can't be changed.
* 
* Assume 8N1 for all port settings.
*
* @portname 	the filename of the port to initialise.
* 
* @baudrate		baudrate to run the port. 
*/
int clixxIOSerial::begin(const char *portname, long baudrate)
{
    // Setting the baud rate isn't supported if we are using softuart
    softuart_init();

    softuart_turn_rx_on();

    C_iotopen(pMainClass);

    // Enable Interrupts globally for the softuart system to run.
    sei();
    
    return 0;
}
Пример #2
0
/***********************************************************************
 * Name: get_ant_msg
 * 
 * Description: wait and recieve a message from the nRF24AP2
 * 
 * Author(s): Charles Wolf
 * 
 * @param: 
 * 		int	max_wait -> timeout in 1mSec increments
 * 		UCHAR *MSG 	-> pointer to the message array
 * @return:
 * 		int -> 	0 = message timeout
 * 				1 = message recieved
 * Comments:
 * 		ANT Message Structure
 * 			SYNC (0xA4)		1 Byte
 * 			length			1 Byte
 * 			message ID		1 Byte
 * 			Data 			length
 * 			CheckSum		1 Byte
 * 			
 * ********************************************************************/
int get_ant_msg(int max_wait, UCHAR *MSG)
{	
	int count = 0;
	int i = 0;
	int outcome = 0;
	int length = 0;
	int checksum = 0;
	
	softuart_turn_rx_on();	
	softuart_flush_input_buffer();
	
	while((count < max_wait) && (outcome != 1))
	{
		//wait for data
		while((softuart_kbhit() < 1) && (count < max_wait))
		{
			_delay_us(100); // 1bit = 208.333uSec
			count++;
		}
		if ( softuart_kbhit() > 0 )
		{
			outcome = 2; //no sync
			//check for sync
			MSG[0] = softuart_getchar();
			//softuart_getchar() is a possible place to get stuck waiting
			if(MSG[0] == MESG_TX_SYNC) 
			{
				MSG[1] = softuart_getchar(); //length
				length = MSG[1]+2;
				if(length > 17) length = 17; //protect length
				for (i = 0; i < length; i++)
				{
					MSG[i+2] = softuart_getchar();
				}
				checksum = checkSum(&MSG[0], length+3);
				if (checksum != MSG[length+4])
				{
					outcome = 3; //bad checksum
				}
				else
				{
					outcome = 1; //message recieved	
				}
			}
		}
	}
	softuart_turn_rx_off();
	return outcome;
}
Пример #3
0
void init(void)
{
	//ADCSRA = 0xE7;
	ADCSRA = 0x87;
	ADMUX = 2;//(1<<REFS0) + 1;
	ADCSRA |= (1<<ADSC);
	
	BUTTON1_PORTREG |= (1<<BUTTON1_PIN);
	BUTTON2_PORTREG |= (1<<BUTTON2_PIN);
	
    sei();
	
	softuart_init();
	softuart_turn_rx_on(); /* redundant - on by default */
}
Пример #4
0
int main()
{
    resetPin.low();
    resetPin.input();
    ledPin.low();
    ledPin.output();

    // Ensure that whatever is in the EEPROM is null-terminated. If it
    // wasn't yet, we have just been flashed so set the stored
    // timestamp to a null string.
    if (0 != read1EEPROM(sizeof(lastTimestamp))) {
	_cmd_clearmem();
    }

    softuart_init();

    // Setup Timer1.
    TCCR1 = 15;  // Prescaler period 2^14.
    FAST_SET(TCCR1, CTC1);  // CTC mode with OCR1C register.
    // Set the counter interval to 244, which produces the period of
    // just under half a second (timerTick_us).
    OCR1C = 244;
    OCR1A = 244;
    // Timer1 interrupt will only be enabled once the timeout is known.

    sei();

    RecvCmd<16, CMDNUM> cmdReceiver;
    for (byte i = 0; i < CMDNUM; ++i) {
	cmdReceiver.addCommand_P(commandStrings[i]);
    }

    softuart_turn_rx_on();
    for (;;) {
	auto status = cmdReceiver.addChar(softuart_getchar());
	if (status == -2) {
	    softuart_puts_P("Invalid command!\n\r");
	    cmdReceiver.reset();
	} else if (status >= 0) {
	    commands[(byte)status]();
	    cmdReceiver.reset();
	}
    }

    return 0;
}
Пример #5
0
int main(void)
{
	char c;

	unsigned short cnt = 0;
#if (F_CPU > 4000000UL)
#define CNTHALLO (unsigned int)(0xFFFF)
#else 
#define CNTHALLO (unsigned int)(0xFFFF/3)
#endif
	unsigned short mycnt=0;
	  CLKPR=_BV(CLKPCE);
  	CLKPR=0;
	pir=0;

	DDRA |= 0xe2;
	PORTA |= 0x81;
	adc_init();
	softuart_init();
	TCCR1A=_BV(COM0B1)|_BV(WGM00);
	TCCR1B=_BV(CS00);


	softuart_turn_rx_on(); /* redundant - on by default */
	
	sei();
	
	

#if WITH_STDIO_DEMO
		stdio_demo_func();
#endif
OCR1A=0x10;
OCR1B=0xf0;

	
	for (;;) {
	           if((PINB&4)==4 ) pir=1;
	
		if ( softuart_kbhit() ) {
			c = softuart_getchar();
			//softuart_putchar( '[' );
			//softuart_putchar( c );
			//softuart_putchar( ']' );
			if(c=='g')
			  {
			    c=softuart_getchar();
			    if(c==C_ID(ID))
			      {
				softuart_putchar(3);
				softuart_putchar(2);
				send();
			pir=0;
			      }
			  }
			else if( c=='s') 
			  {
			   unsigned int pwm;
			  c=softuart_getchar();
                            if(c==C_ID(ID))
                              {
			      sprintf(line,"made it");
	//		       char line[32];
				for(cnt=0;cnt<=31;cnt++)
				 {
				  c=softuart_getchar();
				  if(c=='\n') {line[cnt]=0; break;}
				  else line[cnt]=c;
				 }
				int ret=sscanf_P(&line[0],PSTR("inTopic/pwm/"STD_ID(ID)" %d"),&pwm);
				sprintf_P(dbg,PSTR("%dpwm:%d"),ret,pwm);
				OCR1B=pwm;	
			
			  }

			 }
			}
		
		
	}
	
	return 0; /* never reached */
}