44 uint8_t mspi_uart_port = MSPI_USART1;
46 void mspi_init(uint8_t cs, uint8_t mode, uint16_t baud){
48 MSPI_CS_PORT_DDR |= (1 << MSPI_CS_PIN_0) | (1 << MSPI_CS_PIN_1) | (1 << MSPI_CS_PIN_2);
49 MSPI_CS_PORT &= ~((1 << MSPI_CS_PIN_0) | (1 << MSPI_CS_PIN_1) | (1 << MSPI_CS_PIN_2));
55 *(usart_ports[mspi_uart_port].UBRRn) = 0;
57 *(usart_ports[mspi_uart_port].XCKn_DDR) |= (1 << usart_ports[mspi_uart_port].XCKn);
59 *(usart_ports[mspi_uart_port].UCSRnC) = ((MSPI_ENABLE) | mode);
61 *(usart_ports[mspi_uart_port].UCSRnB) = ((1 << RXEN0) | (1 << TXEN0));
62 *(usart_ports[mspi_uart_port].UBRRn) = baud;
69 if(spi_current_config != spi_bus_config[cs].checksum){
72 spi_current_config = spi_bus_config[cs].checksum;
76 MSPI_CS_PORT |= cs_bcd[cs];
81 MSPI_CS_PORT &= ~((1 << MSPI_CS_PIN_0) | (1 << MSPI_CS_PIN_1) | (1 << MSPI_CS_PIN_2));
89 while ( !(*(usart_ports[mspi_uart_port].UCSRnA) & (1<<UDRE0)));
90 *(usart_ports[mspi_uart_port].UDRn) = data;
93 while ( !(*(usart_ports[mspi_uart_port].UCSRnA) & (1<<RXC0)) );
94 receive_data = *(usart_ports[mspi_uart_port].UDRn);
100 *(usart_ports[mspi_uart_port].UCSRnA) = MSPI_DISABLE;
101 *(usart_ports[mspi_uart_port].UCSRnB) = MSPI_DISABLE;
102 *(usart_ports[mspi_uart_port].UCSRnC) = MSPI_DISABLE;
107 spi_bus_config[cs].dev_mode = mode;
108 spi_bus_config[cs].dev_baud = baud;
109 spi_bus_config[cs].checksum = mode + baud;
114 *(usart_ports[mspi_uart_port].UBRRn) = 0;
116 *(usart_ports[mspi_uart_port].XCKn_DDR) |= (1 << usart_ports[mspi_uart_port].XCKn);
118 *(usart_ports[mspi_uart_port].UCSRnC) = ((MSPI_ENABLE) | new_config.dev_mode);
120 *(usart_ports[mspi_uart_port].UCSRnB) = ((1 << RXEN0) | (1 << TXEN0));
121 *(usart_ports[mspi_uart_port].UBRRn) = new_config.dev_baud;