Other Parts Discussed in Thread: CC2500
Hello,
I'm using the CC2500 with an ATTiny841. I have successfully tested transmission, but I'm having two serious issues:
- Transmission only works on the first packet, after that it hangs while waiting for SO to go low. If the two while loops are commented it works, but this is poor practice
- The system never receives packets. SO is always high, but it never sees any packets.
I have an Arduino Uno and an ATTiny85 with CC2500s as well. They can communicate, as well as see the first packet sent by the 841 before it locks up.
Code Below (PORTA5 is SO and PORTA0 is CSn):
bool listen_for_packet(uint8_t *packet, uint8_t length)
{
uint8_t received_length;
int i;
send_strobe(CC2500_RX);
//_delay_ms(20);
if (rbi(PORTA, PORTA5)) {
received_length = read_reg(CC2500_RXFIFO);
if (received_length <= length) {
packet[0] = received_length;
for (i = 1; i < received_length; i++)
packet[i] = read_reg(CC2500_RXFIFO);
}
send_strobe(CC2500_IDLE);
send_strobe(CC2500_FRX);
return true;
}
else
return false;
}
void send_packet(uint8_t *packet, uint8_t length)
{
int i;
send_strobe(CC2500_IDLE);
send_strobe(CC2500_FTX);
send_strobe(CC2500_IDLE);
for (i = 0; i < length; i++)
write_reg(CC2500_TXFIFO, packet[i]);
send_strobe(CC2500_TX);
while (!rbi(PORTA, PORTA5)); // wait for MISO to be set
while (rbi(PORTA, PORTA5)); // wait for clear
send_strobe(CC2500_IDLE);
}
void write_reg(uint8_t addr, uint8_t value)
{
cbi(PORTA, PORTA0);
while (rbi(PORTA, PORTA5) == 1);
transmit(addr);
transmit(value);
sbi(PORTA, PORTA0);
}
void send_strobe(uint8_t value)
{
cbi(PORTA, PORTA0);
while (rbi(PORTA, PORTA5) == 1);
transmit(value);
sbi(PORTA, PORTA0);
}
any help would be greatly appreciated