diff --git a/src/main.c b/src/main.c index ed6e267..9e522d7 100644 --- a/src/main.c +++ b/src/main.c @@ -55,6 +55,7 @@ static void zh_pad_interrupt_init(void) static void zh_spi_init(void) { DDRB |= ((1 << PORTB2) | (1 << PORTB3) | (1 << PORTB5)); + PORTB |= (1 << PORTB2); SPCR |= ((1 << SPE) | (1 << MSTR)); } @@ -70,7 +71,8 @@ static uint8_t zh_spi_transfer(uint8_t data) static void zh_nrf24_init(void) { uint64_t gateway_address = GATEWAY_ADDRESS; - DDRB |= (1 << PORTB2); + DDRB |= (1 << PORTB1); + PORTB &= ~(1 << PORTB1); zh_nrf24_write_register(0x00, 0x48); zh_nrf24_write_register(0x01, 0x01); zh_nrf24_write_register(0x02, 0x01); @@ -86,19 +88,23 @@ static void zh_nrf24_init(void) static void zh_nrf24_send(uint8_t *buf, uint8_t size) { zh_nrf24_write_register(0x00, 0x4A); - _delay_ms(2); + _delay_ms(5); + zh_nrf24_send_command(0xE1); zh_nrf24_write_buffer(0xA0, buf, size); PORTB |= (1 << PORTB1); - _delay_us(15); - PORTB &= ~(1 << PORTB1); + uint8_t count = 0; while ((PIND & (1 << PIND2)) != 0) { + if (++count > 100) + { + break; + } _delay_ms(1); } zh_nrf24_write_register(0x07, zh_nrf24_send_command(0xFF)); zh_nrf24_send_command(0xE1); zh_nrf24_write_register(0x00, 0x48); - PORTB &= ~(1 << PORTB2); + PORTB &= ~((1 << PORTB1) | (1 << PORTB2)); } static uint8_t zh_nrf24_write_buffer(uint8_t cmd, uint8_t *buf, uint8_t count)