コード例 #1
0
ファイル: i2c-scan.c プロジェクト: brabo/stm32f4-i2c-scan
int main(void)
{
	clock_setup();
	usart_clock_setup();
	gpio_setup();
	usart_setup();

	printf("\r\nstarting i2c scan.\r\n");

	int i, j;
	for (i = 1; i < 0x80; i++) {
		i2c_init();
		msleep(50);
		for (j = 0; j < 0x100; j++) {
			int data; // = 0;
			data = i2c_read(I2C3, i, j);
			if (data > -1) {
				if (data) {
					printf("device on address 0x%02X : reg = 0x%02X with data == 0x%02X\r\n", i, j, data);
				}
			} else {
				printf("errerr!!\r\n");
				break;
			}
			//i2c_send_stop(I2C3);
		}
		i2c_deinit();
		msleep(50);
	}
	printf("scan ended!\r\n");
	return 0;
}
コード例 #2
0
ファイル: usart.c プロジェクト: BG2BKK/STM32-USB-Keyboard
void usart_setup(void)
{
	usart_clock_setup();
	usart_gpio_setup();

	nvic_enable_irq(NVIC_USART2_IRQ);

	/* Setup USART2 parameters. */
	usart_set_baudrate(USART2, 115200);
	usart_set_databits(USART2, 8);
	usart_set_stopbits(USART2, USART_STOPBITS_1);
	usart_set_mode(USART2, USART_MODE_TX | USART_MODE_RX);
	usart_set_parity(USART2, USART_PARITY_NONE);
	usart_set_flow_control(USART2, USART_FLOWCONTROL_NONE);

	/* Enable USART2 Receive interrupt. */
	usart_enable_rx_interrupt(USART2);

	/* Finally enable the USART. */
	usart_enable(USART2);

    /* Disable stupid output buffers. */
	setbuf(stdout, NULL);
}