Beispiel #1
0
int main()
{
	i2c_init();
	uart_init();
	while(1)
	{
		   	uart_tx_str("\r\nReading from eeprom\r\n");
			eeprom_read();
			uart_tx_str("\r\nDONE!!\r\n");
	}
}
Beispiel #2
0
/**@brief Function for application main entry.
 */
int main(void) {
// Initialize
	leds_init();
	timers_init();
	gpiote_init();
	buttons_init();
	simple_uart_config(UART_RTS, UART_TX, UART_CTS, UART_RX, 0);
	ble_stack_init();
	scheduler_init();
	gap_params_init();
	services_init();
	advertising_init();
	conn_params_init();
	sec_params_init();
// Start execution
	//app_button_enable();
	advertising_start();
	uart_tx_str("nRF51822 run");

// Enter main loop

	for (;;) {
		app_sched_execute();
		power_manage();
	}
}
Beispiel #3
0
void state_machine(int8_t ch){
	static int8_t state = ST_IDLE;
	switch(state){
	case ST_IDLE:
		uart_tx_str((uint8_t*)"STATE_IDLE ENTERED\n");
		if (ch == MOTOR_ONE)
			state = ST_ONE;
		else if (ch == MOTOR_TWO)
			state = ST_TWO;
		else
			state = ST_POS1;
		break;
	case ST_ONE:
		uart_tx_str((uint8_t*)"STATE_MOTOR_ONE ENTERED\n");
		if (ch == 0)
			m_one_ctrl(M_ONE_STOP, 0);
		else if (ch > 0)
			m_one_ctrl(M_ONE_FWD, ch);
		else if (ch < 0)
			m_one_ctrl(M_ONE_REV, ch);
		state = ST_IDLE;
		break;
	case ST_TWO:
		uart_tx_str((uint8_t*)"STATE_MOTOR_TWO ENTERED\n");
		if (ch == 0)
			m_two_ctrl(M_TWO_STOP, 0);
		else if (ch > 0)
			m_two_ctrl(M_TWO_FWD, ch);
		else if (ch < 0)
			m_two_ctrl(M_TWO_REV, ch);
		else
			state = ST_POS2;
		state = ST_IDLE;
		break;
	case ST_POS1:
		uart_tx_str((uint8_t*)"STATE_FAIL_POS1\n");
		state = ST_IDLE;
		break;
	case ST_POS2:
		uart_tx_str((uint8_t*)"STATE_FAIL_POS2\n");
		state = ST_IDLE;
		break;
	}
}
void init_all() {
  DDRC |= _BV(PC5);
  PORTC |= _BV(PC5);
  _delay_ms(5000);
  PORTC &= !_BV(PC5);

	uart_init(ISR_STATE);		
	kb_init();			
	pwm_init();			
	uart_tx_str("Booted up correctly!\r\n");	
	sei();		
	
}
Beispiel #5
0
int main()
{
	i2c_init();
	uart_init();
	uart_tx_str("Starting program!!\r\n");
	while(1)
	{
		I2C0CONCLR = 0XFF;			// Clearin I2C0CONSET
		I2C0CONSET	=  I2EN|AA;		// Enable I2C and set AA
		I2C0CONSET	|=	STA;		// i2c start
		while(done);
		done=1;
	}
}
Beispiel #6
0
void eeprom_read()
{
	/***********************WRITING DATA*************************************/
	start();
	uart_tx_str("\r\nhere\r\n");
	devadd1();
	location(0x00);
	stop();
	
	/******************************************READ********************************************/
	start();
	devadd2();
	for(j=0;j<=5;j++)
	{
		uart_tx_char(readdata());
	}

	stop();
}
Beispiel #7
0
Datei: uart.c Projekt: rargo/app
void uart_test3(void)
{
	int ret;
	char buf[1024];
	int i;
	volatile int j;

	for(i = 0; i<sizeof(buf); i++)
		buf[i] = i & 0xff;

	/* uart3 tx test */
	ret = uart_open(3,115200,8,'n',1);
	dprintf("open uart 3 ret:%d\r\n", ret);

	for(;;) {
		uart_tx_str(3, "AT\r");
		while(!uart_tx_finish(3))
			;

		while(!(ret = uart_rx(3, buf, sizeof(buf))))
			;

		if(ret < 0) {
			RERR();
			continue;
		}

		j = 1000;
		while(j--)
			;
		ret += uart_rx(3, buf + ret, sizeof(buf));
		if(ret > 0) {
			buf[ret] = 0;
			dprintf("ret:%d buf:%s\r\n",ret, buf);
		} else {
			dprintf("uart rx 3 ret:%d\r\n",ret);
		}
	}

	uart_close(3);
}
int main(void)
{
	struct Hamming_config* conf = hamming_generate_config();
	i = 1;
	j = 0;
    data = matrix_generate(N,1);

	#ifdef DEBUG
		//Setup led for debugging
        //LED_DDR |= LED_PIN_MASK;
        //LED_PORT &=~LED_PIN_MASK;
	#endif
	uart_init(BAUD_RATE);

    // Pin change interrupt (INT1 pin)
    EICRA |= (1 << ISC11); // Falling edge
    EIMSK |= (1 << INT1); // Enable Interruption
    EIFR |= (1 << INTF1);

	char str[5];
	// Enable interrupts.
	sei();

    //Main loop
	for(;;)
	{
		sprintf(str, "%d\n", freeRam());
		uart_tx_str(str);
	    if(i == 8)
        {
			struct Matrix* tmp = hamming_correction(data, conf);
			struct Matrix* deco = hamming_decode(tmp, conf);
			data_show(deco->data);
			matrix_free(tmp);
			matrix_free(deco);
			i = 1;
        }
	}
}
Beispiel #9
0
 int main()
 {
 	int x,y,z;
	adc_init();
	uart_init();

	lcd_init();	delay(100);
	
	lcd_char('a');
 	
	while(1) 
	{	cmd(0x01); // Clear LCD
		
		AD0CR = 0x01200600; // ADC Stop, select Channel 0
		//AD0CR |= 0x01000000;  // Start ADC, Channel 0
		x = read_adc();
		cmd(0x80);
		lcd_int(x);
		uart_tx_num(x);
		uart_tx_char(' ');
		
		AD0CR = 0x01200602;
		//AD0CR |= 0x01000000;  // Start ADC, Channel 0
		y = read_adc();
		cmd(0x85); 
		lcd_int(y);
		uart_tx_num(y);
		uart_tx_char(' ');

		
	
		AD0CR = 0x01200604;
		//AD0CR |= 0x01000000;  // Start ADC, Channel 0
		z = read_adc();
		cmd(0x8A); 
		lcd_int(z);
		uart_tx_num(z);
		uart_tx_str("\r");

				  
		if(x>600 )
		{
			cmd(0x01);
			lcd_str("ALERT x = ");
			uart_tx_str("\nAlert x");
			cmd(0xc0);
			lcd_int(x);
			delay(1000);
			cmd(0x01);
		}
		if(y<300 )
		{
			cmd(0x01);
			lcd_str("ALERT y = ");
			uart_tx_str("\nAlert y");
			cmd(0xc0);
			lcd_int(y);
			delay(1000);
			cmd(0x01);
		}
		delay(100);	
		
			

	}
 	
 }
Beispiel #10
0
/**@brief Function for handling the Application's BLE Stack events.
 *
 * @param[in] p_ble_evt Bluetooth stack event.
 */
static void on_ble_evt(ble_evt_t * p_ble_evt) {
	uint32_t err_code = NRF_SUCCESS;
	static ble_gap_evt_auth_status_t m_auth_status;
	ble_gap_enc_info_t * p_enc_info;
	switch (p_ble_evt->header.evt_id) {
	case BLE_GAP_EVT_CONNECTED:
		nrf_gpio_pin_set(CONNECTED_LED_PIN_N);
		nrf_gpio_pin_clear(ADVERTISING_LED_PIN_N);
		m_conn_handle = p_ble_evt->evt.gap_evt.conn_handle;

		err_code = app_button_enable();
		break;
	case BLE_GAP_EVT_DISCONNECTED:
		nrf_gpio_pin_clear(CONNECTED_LED_PIN_N);
		m_conn_handle = BLE_CONN_HANDLE_INVALID;

		err_code = app_button_disable();
		if (err_code == NRF_SUCCESS) {
			advertising_start();
		}
		break;
	case BLE_GAP_EVT_SEC_PARAMS_REQUEST:
		err_code = sd_ble_gap_sec_params_reply(m_conn_handle,
				BLE_GAP_SEC_STATUS_SUCCESS, &m_sec_params);
		break;
	case BLE_GATTS_EVT_SYS_ATTR_MISSING:
		err_code = sd_ble_gatts_sys_attr_set(m_conn_handle, NULL, 0);
		break;

	case BLE_GAP_EVT_AUTH_STATUS:
		m_auth_status = p_ble_evt->evt.gap_evt.params.auth_status;
		break;
	case BLE_GAP_EVT_SEC_INFO_REQUEST:
		p_enc_info = &m_auth_status.periph_keys.enc_info;
		if (p_enc_info->div
				== p_ble_evt->evt.gap_evt.params.sec_info_request.div) {
			err_code = sd_ble_gap_sec_info_reply(m_conn_handle, p_enc_info,
					NULL);
		} else {
// No keys found for this device
			err_code = sd_ble_gap_sec_info_reply(m_conn_handle, NULL, NULL);
		}
		break;

	case BLE_GAP_EVT_TIMEOUT:
		if (p_ble_evt->evt.gap_evt.params.timeout.src
				== BLE_GAP_TIMEOUT_SRC_ADVERTISEMENT) {
			nrf_gpio_pin_clear(ADVERTISING_LED_PIN_N);

// Go to system-off mode (this function will not return; wakeup will cause a reset)
			GPIO_WAKEUP_BUTTON_CONFIG(WAKEUP_BUTTON_PIN);
			uart_tx_str("reset by timeout");
			err_code = sd_power_system_off();
		}
		break;

	case BLE_GATTS_EVT_WRITE:
		break;

	case BLE_GAP_EVT_CONN_PARAM_UPDATE:
		nrf_gpio_pin_toggle (LEDBUTTON_LED_PIN_NO);
		break;

	default:
		break;
	}

	APP_ERROR_CHECK(err_code);
}
Beispiel #11
0
/**@brief Callback function for asserts in the SoftDevice.
 *
 * @details This function will be called in case of an assert in the SoftDevice.
 *
 * @warning This handler is an example only and does not fit a final product. You need to analyze
 * how your product is supposed to react in case of Assert.
 * @warning On assert from the SoftDevice, the system can only recover on reset.
 *
 * @param[in] line_num Line number of the failing ASSERT call.
 * @param[in] file_name File name of the failing ASSERT call.
 */
void assert_nrf_callback(uint16_t line_num, const uint8_t * p_file_name) {
	app_error_handler(DEAD_BEEF, line_num, p_file_name);
	uart_tx_str("error happens");
}