/**
 * \brief Application entry point for AT30TS(E)75x Component Example.
 *
 * \return Unused (ANSI-C compatibility).
 */
int main(void)
{
	double temp = 0;

	/* Initialize the SAM system */
	sysclk_init();

	/* Initialize the board */
	board_init();

	/* Initialize the console UART */
	configure_console();

	/* Output example information */
	puts(STRING_HEADER);

	memset(tx, 0xFF, NB_BYTE);

	/* Initialize AT30TS(E)75x */
	at30tse_init();

#if BOARD_USING_AT30TSE != AT30TS75
	uint32_t i;
	/* Write pages in EEPROM */
	for (i = 0; i < NB_PAGE; i++) {
		tx[NB_PAGE - 1] = i;
		if (at30tse_eeprom_write(tx, NB_BYTE, 0, i) != TWI_SUCCESS) {
			puts("Write EEPROM error\r");
			return 0;
		}
		delay_ms(5);
	}
	puts("Write EEPROM OK\r");

	/* Read each page in EEPROM and compare them */
	for (i = 0; i < NB_PAGE; i++) {
		memset(rx, 0, NB_BYTE);
		if (at30tse_eeprom_read(rx, NB_BYTE, 0, i) != TWI_SUCCESS) {
			puts("Read EEPROM error\r");
			return 0;
		} else {
			if (memcmp(tx, rx, NB_BYTE - 1) && (rx[NB_PAGE - 1] != i)) {
				puts("Comparison error\r");
				return 0;
			}
		}
	}
	puts("Read EEPROM & Compare OK\r");
#endif

	/* Read temperature every second */
	while (1) {
		if (at30tse_read_temperature(&temp) != TWI_SUCCESS) {
			puts("Read temperature error\r");
			return 0;
		}
		printf("Read temperature:\t%d\r\n", (int)temp);
		delay_ms(1000);
	}
}
示例#2
0
/**
 * \brief Application entry point for AT30TS(E)75x unit tests.
 *
 * \return Unused (ANSI-C compatibility).
 */
int main(void)
{
	const usart_serial_options_t usart_serial_options = {
		.baudrate   = CONF_TEST_BAUDRATE,
		.charlength = CONF_TEST_CHARLENGTH,
		.paritytype = CONF_TEST_PARITY,
		.stopbits   = CONF_TEST_STOPBITS
	};

	sysclk_init();
	board_init();
	/* Initialize AT30TS(E)75x */
	at30tse_init();

	stdio_serial_init(CONF_TEST_USART, &usart_serial_options);

	/* Define all the test cases */
	DEFINE_TEST_CASE(at30tse_test_read_temperature,
			NULL, run_test_read_temperature, NULL,
			"at30tse read temperature test");
#if BOARD_USING_AT30TSE != AT30TS75
	DEFINE_TEST_CASE(at30tse_test_write_data,
			NULL, run_test_write_data, NULL,
			"at30tse write data test");
	DEFINE_TEST_CASE(at30tse_test_read_data,
			NULL, run_test_read_compare_data, NULL,
			"at30tse read and compare data test");
#endif
	/* Put test case addresses in an array */
	DEFINE_TEST_ARRAY(at30tse_test_array) = {
			&at30tse_test_read_temperature,
#if BOARD_USING_AT30TSE != AT30TS75
			&at30tse_test_write_data,
			&at30tse_test_read_data,
#endif
	};

	/* Define the test suite */
	DEFINE_TEST_SUITE(at30tse_suite, at30tse_test_array,
			"at30tse driver test suite");

	/* Run all tests in the test suite */
	test_suite_run(&at30tse_suite);

	while (1) {
		/* Busy-wait forever */
	}
}
示例#3
0
int main(void)
{
//! [init]
	/* Init system. */
//! [system_init]
	system_init();
//! [system_init]
	/* Configure device and enable. */
//! [temp_init]
	at30tse_init();
//! [temp_init]
//! [init]

//! [impl]
    /* Read thigh and tlow */
//! [read_thigh]
	volatile uint16_t thigh = 0;
	thigh = at30tse_read_register(AT30TSE_THIGH_REG,
			AT30TSE_NON_VOLATILE_REG, AT30TSE_THIGH_REG_SIZE);
//! [read_thigh]
//! [read_tlow]
	volatile uint16_t tlow = 0;
	tlow = at30tse_read_register(AT30TSE_TLOW_REG,
			AT30TSE_NON_VOLATILE_REG, AT30TSE_TLOW_REG_SIZE);
//! [read_tlow]

	/* Set 12-bit resolution mode. */
//! [write_conf]
	at30tse_write_config_register(
			AT30TSE_CONFIG_RES(AT30TSE_CONFIG_RES_12_bit));
//! [write_conf]

//! [read_temp]
	while (1) {
		temp_res = at30tse_read_temperature();
	}
//! [read_temp]
//! [impl]
	UNUSED(tlow);
	UNUSED(thigh);
}
示例#4
0
文件: main.c 项目: AndreyMostovov/asf
/**
 * \brief The main application.
 */
int main(void)
{
	uint8_t i;
	uint8_t temperature[BUFFER_SIZE];
	uint8_t light[BUFFER_SIZE];
	char value_disp[5];
	uint32_t adc_value;
	uint32_t light_value;
	double temp;

	/* Initialize clocks. */
	sysclk_init();

	/* Initialize GPIO states. */
	board_init();

	/* Configure ADC for light sensor. */
	configure_adc();

	/* Initialize at30tse. */
	at30tse_init();

	/* Configure IO1 buttons. */
	configure_buttons();

	/* Initialize SPI and SSD1306 controller. */
	ssd1306_init();
	ssd1306_clear();

	/* Clear internal buffers. */
	for (i = 0; i < BUFFER_SIZE; ++i) {
		temperature[i] = 0;
		light[i] = 0;
	}

	/* Show the start info. */
	multi_language_show_start_info();

	/* Wait 3 seconds to show the above message. */
	delay_s(3);

	/* Check for valid firmware in SD card. */
	check_valid_firmware();

	while (true) {
		/* Set the trigger and jump to bootloader */
		if (reset_flag) {
			jump_to_bootloader();
		}

		/* Refresh page title only if necessary. */
		if (app_mode_switch > 0) {
			app_mode = (app_mode + 1) % 3;

			/* Clear screen. */
			ssd1306_clear();
			ssd1306_set_page_address(0);
			ssd1306_set_column_address(0);

			if (app_mode == 0) {
				/* Temperature mode. */
				ioport_set_pin_level(OLED1_LED1_PIN, OLED1_LED1_ACTIVE);
				ioport_set_pin_level(OLED1_LED2_PIN, !OLED1_LED2_ACTIVE);
				ioport_set_pin_level(OLED1_LED3_PIN, !OLED1_LED3_ACTIVE);
				multi_language_show_temperature_info();
			} else if (app_mode == 1) {
				/* Light mode. */
				ioport_set_pin_level(OLED1_LED2_PIN, OLED1_LED2_ACTIVE);
				ioport_set_pin_level(OLED1_LED1_PIN, !OLED1_LED1_ACTIVE);
				ioport_set_pin_level(OLED1_LED3_PIN, !OLED1_LED3_ACTIVE);
				multi_language_show_light_info();
			} else {
				/* SD mode. */
				ioport_set_pin_level(OLED1_LED3_PIN, OLED1_LED3_ACTIVE);
				ioport_set_pin_level(OLED1_LED1_PIN, !OLED1_LED1_ACTIVE);
				ioport_set_pin_level(OLED1_LED2_PIN, !OLED1_LED2_ACTIVE);

				sd_listing_pos = 0;
				/* Show SD card info. */
				display_sd_info();
			}

			app_mode_switch = 0;
		}

		/* Shift graph buffers. */
		for (i = 0; i < (BUFFER_SIZE - 1); ++i) {
			temperature[i] = temperature[i + 1];
			light[i] = light[i + 1];
		}

		/* Get temperature. */
		if (at30tse_read_temperature(&temp) == TWI_SUCCESS) {
			/* Don't care about negative temperature. */
			if (temp < 0) {
				temp = 0;
			}

			/* Update temperature for display. */
			/* Note: rescale to 0~24 for better rendering. */
			if (temp > 40) {
				temperature[BUFFER_SIZE - 1] = 24;
			} else {
				temperature[BUFFER_SIZE - 1] = (uint8_t)temp * 24 / 40;
			}
		} else {
			/* Error print zero values. */
			temperature[BUFFER_SIZE - 1] = 0;
		}

		/* Get light sensor information. */
		/* Rescale to 0~24 for better rendering. */
		adc_start_software_conversion(ADC);
		adc_value = adc_channel_get_value(ADC, ADC_CHANNEL_0);
		light[BUFFER_SIZE - 1] = 24 - adc_value * 24 / 1024;

		if (app_mode == 0) {
			/* Display temperature in text format. */
			sprintf(value_disp, "%d", (uint8_t)temp);
			ssd1306_set_column_address(98);
			ssd1306_write_command(SSD1306_CMD_SET_PAGE_START_ADDRESS(0));
			ssd1306_write_text(" ");
			/* Avoid character overlapping. */
			if (temp < 10) {
				ssd1306_clear_char();
			}

			ssd1306_write_text(value_disp);
			/* Display degree symbol. */
			ssd1306_write_data(0x06);
			ssd1306_write_data(0x06);
			ssd1306_write_text("c");

			/* Refresh graph. */
			ssd1306_draw_graph(0, 2, BUFFER_SIZE, 2, temperature);
		} else if (app_mode == 1) {
			light_value = 100 - (adc_value * 100 / 1024);
			sprintf(value_disp, "%lu", light_value);
			ssd1306_set_column_address(98);
			ssd1306_write_command(SSD1306_CMD_SET_PAGE_START_ADDRESS(0));
			ssd1306_write_text(" ");
			/* Avoid character overlapping. */
			if (light_value < 10) {
				ssd1306_clear_char();
			}

			ssd1306_write_text(value_disp);
			ssd1306_write_text("%");
			/* Avoid character overlapping. */
			if (light_value < 100) {
				ssd1306_clear_char();
			}

			/* Refresh graph. */
			ssd1306_draw_graph(0, 2, BUFFER_SIZE, 2, light);
		} else {
			/**
			 * Refresh screen if card was inserted/removed or
			 * browsing content.
			 */
			if (sd_update == 1) {
				/* Clear screen. */
				ssd1306_clear();
				ssd1306_set_page_address(0);
				ssd1306_set_column_address(0);

				if (sd_listing_pos == 0) {
					/* Show SD card info. */
					display_sd_info();
				} else {
					/* List SD card files. */
					display_sd_files_unicode();
				}

				sd_update = 0;
			}
		}

		/* Wait and stop screen flickers. */
		delay_ms(150);

		if (app_mode_switch == 0) {
			pio_enable_interrupt(OLED1_PIN_PUSHBUTTON_1_PIO,
					OLED1_PIN_PUSHBUTTON_1_MASK);
		}
		if (sd_update == 0) {
			pio_enable_interrupt(OLED1_PIN_PUSHBUTTON_2_PIO,
					OLED1_PIN_PUSHBUTTON_2_MASK);
			pio_enable_interrupt(OLED1_PIN_PUSHBUTTON_3_PIO,
					OLED1_PIN_PUSHBUTTON_3_MASK);
		}

	}
}
示例#5
0
int main(void)
{
	volatile double temper_value;
	volatile bool data_check_status1 = true,
	              data_check_status2 = true;
	uint32_t i;

	system_clock_config(CLOCK_RESOURCE_XO_26_MHZ, CLOCK_FREQ_26_MHZ);

	/* Initialize AT30TS(E)75x */
	at30tse_init();

	/* First round data check */
	for (i = 0; i < NB_BYTE; i++) {
		tx_buffer[i] = i;
	}

	/* Write pages in EEPROM */
	for (i = 0; i < NB_PAGE; i++) {
		at30tse_eeprom_write(tx_buffer, NB_BYTE, 0, i);
		delay(200);
	}
	
	/* Read each page in EEPROM and compare them */
	for (i = 0; i < NB_PAGE; i++) {
		memset(rx_buffer, 0, NB_BYTE);
		at30tse_eeprom_read(rx_buffer, NB_BYTE, 0, i);
		if (memcmp(tx_buffer, rx_buffer, NB_BYTE)) {
			data_check_status1 = false;
			break;
		}
	}

	/* Second round data check */
	for (i = 0; i < NB_BYTE; i++) {
		tx_buffer[i] = NB_BYTE - i;
	}

	/* Write pages in EEPROM */
	for (i = 0; i < NB_PAGE; i++) {
		at30tse_eeprom_write(tx_buffer, NB_BYTE, 0, i);
		delay(200);
	}
	
	/* Read each page in EEPROM and compare them */
	for (i = 0; i < NB_PAGE; i++) {
		memset(rx_buffer, 0, NB_BYTE);
		at30tse_eeprom_read(rx_buffer, NB_BYTE, 0, i);
		if (memcmp(tx_buffer, rx_buffer, NB_BYTE)) {
			data_check_status2 = false;
			break;
		}
	}

	/* Read thigh and tlow */
	volatile uint16_t thigh = 0;
	thigh = at30tse_read_register(AT30TSE_THIGH_REG,
			AT30TSE_NON_VOLATILE_REG, AT30TSE_THIGH_REG_SIZE);

	volatile uint16_t tlow = 0;
	tlow = at30tse_read_register(AT30TSE_TLOW_REG,
			AT30TSE_NON_VOLATILE_REG, AT30TSE_TLOW_REG_SIZE);
			
	/* Set 12-bit resolution mode. */
	at30tse_write_config_register(
			AT30TSE_CONFIG_RES(AT30TSE_CONFIG_RES_12_bit));

	while (1) {
		/* Read current temperature. */
		temper_value = at30tse_read_temperature();
	}

	UNUSED(data_check_status1);
	UNUSED(data_check_status2);
	UNUSED(temper_value);
	UNUSED(tlow);
	UNUSED(thigh);
}
示例#6
0
int main(void)
{
	uint8_t i;
	uint8_t temperature[BUFFER_SIZE];
	uint8_t light[BUFFER_SIZE];
	uint8_t value_disp[5];
	uint32_t adc_value;
	double temp;

	// Initialize clocks.
	sysclk_init();

	// Initialize GPIO states.
	board_init();

	// Configure ADC for light sensor.
	configure_adc();

	// Initialize at30tse.
	at30tse_init();

	// Configure IO1 buttons.
	configure_buttons();

	// Initialize SPI and SSD1306 controller.
	ssd1306_init();
	ssd1306_clear();

	// Clear internal buffers.
	for (i = 0; i < BUFFER_SIZE; ++i)
	{
		temperature[i] = 0;
		light[i] = 0;
	}

	while (true)
	{
		/* Refresh page title only if necessary. */
		if (app_mode_switch > 0)
		{
			app_mode = app_mode_switch - 1;

			// Clear screen.
			ssd1306_clear();
			ssd1306_set_page_address(0);
			ssd1306_set_column_address(0);

			/* Temperature mode. */
			if (app_mode == 0)
			{
				ioport_set_pin_level(IO1_LED1_PIN, IO1_LED1_ACTIVE);
				ioport_set_pin_level(IO1_LED2_PIN, !IO1_LED2_ACTIVE);
				ioport_set_pin_level(IO1_LED3_PIN, !IO1_LED3_ACTIVE);
				ssd1306_write_text("Temperature sensor:");
			}
			/* Light mode. */
			else if (app_mode == 1)
			{
				ioport_set_pin_level(IO1_LED2_PIN, IO1_LED2_ACTIVE);
				ioport_set_pin_level(IO1_LED1_PIN, !IO1_LED1_ACTIVE);
				ioport_set_pin_level(IO1_LED3_PIN, !IO1_LED3_ACTIVE);
				ssd1306_write_text("Light sensor:");
			}
			/* SD mode. */
			else
			{
				ioport_set_pin_level(IO1_LED3_PIN, IO1_LED3_ACTIVE);
				ioport_set_pin_level(IO1_LED1_PIN, !IO1_LED1_ACTIVE);
				ioport_set_pin_level(IO1_LED2_PIN, !IO1_LED2_ACTIVE);

				display_sd_info();
			}
			app_mode_switch = 0;
		}

		// Shift graph buffers.
		for (i = 0; i < BUFFER_SIZE - 1; ++i)
		{
			temperature[i] = temperature[i + 1];
			light[i] = light[i + 1];
		}

		// Get temperature in a range from 0 to 40 degrees.
		if (at30tse_read_temperature(&temp) == TWI_SUCCESS)
		{
			// Don't care about negative temperature.
			if (temp < 0)
				temp = 0;

			// Update temperature for display.
			// Note: -12 in order to rescale for better rendering.
			if (temp < 12)
				temperature[BUFFER_SIZE - 1] = 0;
			else
				temperature[BUFFER_SIZE - 1] = temp - 12;
		}
		else
		{
			// Error print zero values.
			temperature[BUFFER_SIZE - 1] = 0;
		}

		// Get light sensor information.
		// Rescale for better rendering.
		adc_start(ADC);
		adc_value = adc_get_channel_value(ADC, ADC_CHANNEL_4);
		light[BUFFER_SIZE - 1] = 24 - adc_value * 24 / 4096;

		// Print temperature in text format.
		if (app_mode == 0)
		{
			sprintf(value_disp, "%d", (uint8_t)temp);
			ssd1306_set_column_address(95);
			ssd1306_write_command(SSD1306_CMD_SET_PAGE_START_ADDRESS(0));
			ssd1306_write_text(" ");
			ssd1306_write_text(value_disp);
			// Display degree symbol.
			ssd1306_write_data(0x06);
			ssd1306_write_data(0x06);
			ssd1306_write_text("c");

			// Refresh graph.
			ssd1306_draw_graph(0, 1, BUFFER_SIZE, 3, temperature);
		}
		else if (app_mode == 1)
		{
			sprintf(value_disp, "%lu", 100 - (adc_value * 100 / 4096));
			ssd1306_set_column_address(98);
			ssd1306_write_command(SSD1306_CMD_SET_PAGE_START_ADDRESS(0));
			ssd1306_write_text(" ");
			ssd1306_write_text(value_disp);
			ssd1306_write_text("%");

			// Refresh graph.
			ssd1306_draw_graph(0, 1, BUFFER_SIZE, 3, light);
		}
		else
		{
			// Is card has been inserted or removed?
			if (sd_status_update == 1)
			{
				// Clear screen.
				ssd1306_clear();
				ssd1306_set_page_address(0);
				ssd1306_set_column_address(0);

				// Show SD card info.
				display_sd_info();

				sd_status_update = 0;
			}

		}

		/* Wait and stop screen flickers. */
		delay_ms(50);
	}
}