Exemple #1
0
void bt_init( void )
{
	uint8_t num_baudrates = sizeof(baudrates)/sizeof(uint32_t);
	uint8_t i = 0;
	int16_t received;

	/* first set BT module AT mode pin */
	io_on( HC05_CMD_PORT, HC05_CMD_PIN);
	/* now wait 100ms */
	delay(100);

	/* iterate through baudrates */
	do
	{
		usart_config_baudrate( baudrates[i]);
		usart_flush();
		/* send AT command */
		usart_transmit( (uint8_t *)BTCMD_AT, BTCMD_AT_LEN);
		/* wait for response */
		received = usart_receive( response_buffer, 4, RESPONSE_TIMEOUT);

		/* we found a valid answer */
		if( received > 0)
		{
			break;
		}
		i++;
	}while(i < num_baudrates);

	if( i > 0)
	{
		/* module seems to be configured for default -> reprogram */
		usart_transmit( (uint8_t *)BTCMD_SET_NAME, BTCMD_SET_NAME_LEN);
		received = usart_receive( response_buffer, RESPONSE_LENGTH, RESPONSE_TIMEOUT);
		/* module seems to be configured for default -> reprogram */
		usart_transmit( (uint8_t *)BTCMD_SET_PW, BTCMD_SET_PW_LEN);
		received = usart_receive( response_buffer, RESPONSE_LENGTH, RESPONSE_TIMEOUT);
		/* module seems to be configured for default -> reprogram */
		usart_transmit( (uint8_t *)BTCMD_SET_BAUD, BTCMD_SET_BAUD_LEN);
		received = usart_receive( response_buffer, RESPONSE_LENGTH, RESPONSE_TIMEOUT);
	}


	/* send reset */
	usart_transmit( (uint8_t *)BTCMD_RESET, BTCMD_RESET_LEN);
	received = usart_receive( response_buffer, RESPONSE_LENGTH, RESPONSE_TIMEOUT);
	/* leave AT mode */
	io_off( HC05_CMD_PORT, HC05_CMD_PIN);
	/* wait a bit */
	delay( 100);
	usart_config_baudrate( baudrates[0]);
	usart_flush();

	bt_ready = 1;

}
void modbus_cycle()
{
  // Wenn nichts mehr zu senden und etwas im Empfangspuffer ist und eine Pause von min 3ms entstanden ist
  // dann Telegramm auswerten
  if (usart_write_len()==0 && usart_read_len()>0 && usart_rx_getdelay()>2)
  { 
    modbus_processSlaveFrame(usart_rx_buffer, usart_read_len());
    // nach der Auswertung Puffer rücksetzen, damit vom Anfang an neu gelesen wird
	  usart_flush();  
  }  
}
Exemple #3
0
int lambda_init(void)
{
	uint8_t i;

	for(i=0;i<128;i++)  O2Mem.Mem[i] = 0;
  
  sprintf(O2Mem.cur_value, "XXX");
  // USART �ffnen
  if((lambda_fd = usart_open( "/dev/ttyAMA0",115200)) == -1)
    return -1;
  
  // Einstellungen senden
  usart_puts(lambda_fd, NORMAL_MODE);
  usart_puts(lambda_fd, LOW_COMMUNICATION);
  usart_puts(lambda_fd, CSVTEXT_MODE);
  
  usart_flush(lambda_fd);
  
  is_Init = true;
}
Exemple #4
0
int main(void) {
	char tmp[256];

	const char message[] = 
			"This royal throne of kings, this scepter'd isle, \n"
			"This earth of majesty, this seat of Mars, \n" /*
			"This other Eden, demi-paradise, \n" 
			"This fortress built by Nature for herself\n"
			"Against infection and the hand of war, \n"
			"This happy breed of men, this little world,\n" 
			"This precious stone set in the silver sea, \n"
			"Which serves it in the office of a wall, \n"
			"Or as a moat defensive to a house, \n"
			"Against the envy of less happier lands, \n"
			"This blessed plot, this earth, this realm, this England,"*/
	;
	const uint16 messlen = strlen(message);
	
	cmcore_init();
	usart_init(&Serial6, USART6, PC7, PC6);
	usart_begin(&Serial6, 57600);

	spi_init(&spi1, SPI1, PA5, PA6, PA7, PA4);
	spi_begin(&spi1);

	usart_print(&Serial6, "Basic initialization has been finished.\n");
		
	RCC_ClocksTypeDef RCC_Clocks;
	RCC_GetClocksFreq(&RCC_Clocks);
	
	usart_print(&Serial6, message);
	usart_print(&Serial6, "\r\n\r\n");
	usart_flush(&Serial6);

	sprintf(tmp, "Clock frequencies: SYSCLK = %dl, HCLK = %dl, PCLK1 = %dl\r\n", 
		RCC_Clocks.SYSCLK_Frequency, RCC_Clocks.HCLK_Frequency, RCC_Clocks.PCLK1_Frequency);
	usart_print(&Serial6, tmp); 

	GPIOMode(PinPort(LED1), (PinBit(LED1) | PinBit(LED2) | PinBit(LED3) | PinBit(LED4)), 
					OUTPUT, FASTSPEED, PUSHPULL, NOPULL);
	
	nokiaLCD.init();
	nokiaLCD.clear();
	nokiaLCD.drawBitmap(PCD8544::SFEFlame);
		delay(1000);
		
	uint16 shift = 0;
	nokiaLCD.selectFont(PCD8544::CHICAGO10);
	
	while (1) {
		nokiaLCD.clear();
		nokiaLCD.cursor(shift);
		nokiaLCD.drawString("Nuke is absolutely safe!");
//		nokiaLCD.drawFont(Nokia5110::Chicago10x15, 'A');
//		nokiaLCD.drawFont(Nokia5110::Chicago10x15, 'W');
		shift++;
		shift %= 252;
		delay(250);

/*
		if ( millis() / 125 != shift ) {
			shift = millis()/ 125;
			nokiaLCD.clear();
			nokiaLCD.gotoXY(7- shift%7,0);
			strncpy(tmp, message+((shift/7) % messlen), 48);
			tmp[48] = 0;
			nokiaLCD.drawString(tmp);
//		usart_print(&Serial6, tmp);
//		usart_print(&Serial6, "\r\n");
		}
		*/
	}
}
Exemple #5
0
int main(void) {
	uint16_t bits;
	uint32_t intval = 40;
	uint32_t tnow;
	char tmp[92];
	RCC_ClocksTypeDef RCC_Clocks;
	uint16_t i;
	
	TIM2_timer_start();

	usart_begin(&USerial3, USART3, PC11, PC10, 19200);

	usart_print(&USerial3, 
			"Happy are those who know they are spiritually poor; \n"
			"The kingdom of heaven belongs to them!\n");
	usart_flush(&USerial3);
	
	RCC_GetClocksFreq(&RCC_Clocks);

	sprintf(tmp, "SYSCLK = %ul\n", RCC_Clocks.SYSCLK_Frequency);
	usart_print(&USerial3, tmp);
	sprintf(tmp, "PCLK1 = %ul\n", RCC_Clocks.PCLK1_Frequency);
	usart_flush(&USerial3);

	GPIOMode(PinPort(PD12),
			(PinBit(PD12) | PinBit(PD13) | PinBit(PD14) | PinBit(PD15)), OUTPUT,
			FASTSPEED, PUSHPULL, NOPULL);
			/*
	spi_begin(SPI2, PB13, PB14, PB15, PB12);
	digitalWrite(PB12, HIGH);
*/
	I2C1_Init();
/*
	i2c_begin(&Wire1, PB9, PB8, 100000);
	lcd.init(&Wire1);
	lcd.begin();
	lcd.setContrast(46);
	lcd.print("Yappee!");       // Classic Hello World!
*/
	bits = GPIO_ReadOutputData(GPIOD );
	GPIOWrite(GPIOD, PinBit(PD13) | (bits & 0x0fff));
	delay_ms(intval);
	tnow = millis() / 1000;
	while (tnow == millis() / 1000)
		;
	tnow = millis() / 1000;

	while (1) {
		bits = GPIO_ReadOutputData(GPIOD );

		GPIOWrite(GPIOD, PinBit(PD13) | (bits & 0x0fff));
		delay_ms(intval);
		GPIOWrite(GPIOD, PinBit(PD14) | (bits & 0x0fff));
		delay_ms(intval);
		GPIOWrite(GPIOD, PinBit(PD15) | (bits & 0x0fff));
		delay_ms(intval);
		GPIOWrite(GPIOD, PinBit(PD12) | (bits & 0x0fff));
		delay_ms(intval);
		//
		bits &= 0x0fff;
		switch ((tnow % 60) / 15) {
		case 3:
			bits |= PinBit(PD12);
		case 2:
			bits |= PinBit(PD15);
		case 1:
			bits |= PinBit(PD14);
		case 0:
		default:
			bits |= PinBit(PD13);
			break;
		}
		GPIOWrite(GPIOD, bits);

		while (tnow == millis() / 1000);
		tnow = millis() / 1000;

		//Serial3.print(tmp);
		sprintf(tmp, "%04ld\n", millis());
		usart_print(&USerial3, tmp);

		/*
		digitalWrite(PB12, LOW);
		spi_transfer(SPI2, (uint8_t *) tmp, 8);
		digitalWrite(PB12, HIGH);
*/
		i = 0;
		if (usart_available(&USerial3) > 0) {
			while (usart_available(&USerial3) > 0 && i < 92) {
				tmp[i++] = (char) usart_read(&USerial3);
			}
			tmp[i] = 0;
			usart_print(&USerial3, "> ");
			usart_print(&USerial3, tmp);
			usart_print(&USerial3, "\n");
		}

	}
	return 0;
}