wip:
This commit is contained in:
16
src/main.c
16
src/main.c
@@ -55,6 +55,7 @@ static void zh_pad_interrupt_init(void)
|
|||||||
static void zh_spi_init(void)
|
static void zh_spi_init(void)
|
||||||
{
|
{
|
||||||
DDRB |= ((1 << PORTB2) | (1 << PORTB3) | (1 << PORTB5));
|
DDRB |= ((1 << PORTB2) | (1 << PORTB3) | (1 << PORTB5));
|
||||||
|
PORTB |= (1 << PORTB2);
|
||||||
SPCR |= ((1 << SPE) | (1 << MSTR));
|
SPCR |= ((1 << SPE) | (1 << MSTR));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -70,7 +71,8 @@ static uint8_t zh_spi_transfer(uint8_t data)
|
|||||||
static void zh_nrf24_init(void)
|
static void zh_nrf24_init(void)
|
||||||
{
|
{
|
||||||
uint64_t gateway_address = GATEWAY_ADDRESS;
|
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(0x00, 0x48);
|
||||||
zh_nrf24_write_register(0x01, 0x01);
|
zh_nrf24_write_register(0x01, 0x01);
|
||||||
zh_nrf24_write_register(0x02, 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)
|
static void zh_nrf24_send(uint8_t *buf, uint8_t size)
|
||||||
{
|
{
|
||||||
zh_nrf24_write_register(0x00, 0x4A);
|
zh_nrf24_write_register(0x00, 0x4A);
|
||||||
_delay_ms(2);
|
_delay_ms(5);
|
||||||
|
zh_nrf24_send_command(0xE1);
|
||||||
zh_nrf24_write_buffer(0xA0, buf, size);
|
zh_nrf24_write_buffer(0xA0, buf, size);
|
||||||
PORTB |= (1 << PORTB1);
|
PORTB |= (1 << PORTB1);
|
||||||
_delay_us(15);
|
uint8_t count = 0;
|
||||||
PORTB &= ~(1 << PORTB1);
|
|
||||||
while ((PIND & (1 << PIND2)) != 0)
|
while ((PIND & (1 << PIND2)) != 0)
|
||||||
{
|
{
|
||||||
|
if (++count > 100)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
_delay_ms(1);
|
_delay_ms(1);
|
||||||
}
|
}
|
||||||
zh_nrf24_write_register(0x07, zh_nrf24_send_command(0xFF));
|
zh_nrf24_write_register(0x07, zh_nrf24_send_command(0xFF));
|
||||||
zh_nrf24_send_command(0xE1);
|
zh_nrf24_send_command(0xE1);
|
||||||
zh_nrf24_write_register(0x00, 0x48);
|
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)
|
static uint8_t zh_nrf24_write_buffer(uint8_t cmd, uint8_t *buf, uint8_t count)
|
||||||
|
Reference in New Issue
Block a user