'==============================[ Config hardware ]==============================
Config Spi = Hard , Interrupt = Off , Data Order = Msb , Master = Yes , Polarity = Low , Phase = 0 , Clockrate = 4 , Noss = 1
'Software SPI is NOT working with the nRF24L01, use hardware SPI only, but the SS pin must be controlled by our self
Ti manda le informazioni sulla porta serial che gia hai sul STK500.e invece qui?
Ti manda le informazioni sulla porta serial che gia hai sul STK500.
Se no l'hai gia scarica un programma Terminal con cui potrai vedere cio' che il chip manda.
Config Pinc.3 = Input 'TX/RX Device _select
If Txrx_device = True Then Goto Main_tx 'Is this the RX or TX device?
'===================================[ Main rx ]=================================
Main_rx:
Call R_register(status , 1) 'Read STATUS register
Print "Rx_device" 'Send to terminal who i'm
Reset Ce 'Set CE low to access the registers
Gosub Setup_rx 'Setup the nRF24L01 for RX
Waitms 2 'Add a delay before going in RX
Set Ce 'Set nRF20L01 in RX mode
Do 'Main loop for RX
If Irq = 0 Then 'Wait until IRQ occurs, pin becomes low on interrupt
Reset Ce 'Receiver must be disabled before reading pload
Do 'Loop until all 3 fifo buffers are empty
Call R_register(rd_rx_pload , 5) 'Read 5 bytes RX pload register
Print "Pload : " ; Hex(b_bytes(1)) ; Hex(b_bytes(2)) ; _
Hex(b_bytes(3)) ; Hex(b_bytes(4)) ; Hex(b_bytes(5)) 'Print the pload
Call R_register(fifo_status , 1) 'Read FIFO_STATUS
Loop Until B_bytes(1).0 = True 'Test or RX_EMPTY bit is true, RX FIFO empty
D_bytes(1) = Write_reg + Status 'Reset the RX_DR status bit
D_bytes(2) = &B01000000 'Write 1 to RX_DR bit to reset IRQ
Call W_register(2)
Set Ce 'Enable receiver again
Waitms 2
End If
'--Gosub Dump_registers 'Unremark me for debugging
Loop
Return
'=====================================[ Main tx ]===============================
Main_tx:
Print "TX_device" 'Send to terminal who i'm
D_bytes(1) = Flush_tx 'Flush the TX_fifo buffer
Call W_register(1)
D_bytes(1) = Write_reg + Status 'Reset the IRQ bits
D_bytes(2) = &B_0011_0000
Call W_register(2)
Do 'Main loop for TX
Incr Packet_count 'Increase the send packet counter, for test only
If Packet_count > 254 Then Packet_count = 0
Gosub Setup_tx 'Setup the nRF240L01 for TX
D_bytes(1) = Wr_tx_pload 'Put 5 bytes in the TX pload buffer
D_bytes(2) = &HAA 'Byte 1
D_bytes(3) = &HBB 'Byte 2
D_bytes(4) = &HCC 'Byte 3
D_bytes(5) = &H11 'Byte 4
D_bytes(6) = Packet_count 'Byte 5 will be increase every loop
Call W_register(6) 'Write 6 bytes to register
Waitms 2
Set Ce 'Set CE for a short moment to transmit the fifo buffer
Waitms 1 '
Reset Ce '
Waitms 100 'Some delay to read the output on the terminal, line can be removed for max. speed
W = 0 'Counter for time out
Do
If Irq = 0 Then
Call R_register(status , 1)
Temp = B_bytes(1) And &B01110000 'Mask the IRQ bits out the status byte
Select Case Temp 'Which IRQ occurs
Case Max_rt 'MAX_RT
Print "Maximum number of TX retries, Flussing the TX buffer now !"
D_bytes(1) = Flush_tx 'Flush the TX buffer
Call W_register(1)
D_bytes(1) = Write_reg + Status
D_bytes(2) = &B00010000 'Clear the MAX_RT IRQ bit
Call W_register(2)
Exit Do
Case Tx_ds 'TX_DS
Print "Packet " ; Packet_count ; " send and ACK received."
D_bytes(1) = Write_reg + Status
D_bytes(2) = &B00100000 'Clear the TX_DS IRQ bit
Call W_register(2)
Exit Do
Case Else 'Other IRQ ??
Print "Other irq " ; Bin(temp)
D_bytes(1) = Flush_tx 'Flush the TX buffer
Call W_register(1)
D_bytes(1) = Write_reg + Status
D_bytes(2) = &B00110000 'Clear both MAX_RT, TX_DS bits
Call W_register(2)
End Select
End If
Waitms 1 'Time out waiting for IRQ 1ms * 100
Incr W 'Increment W
If W > 100 Then 'Waited for 100ms
Print "No irq response from RF20L01 within 100ms"
Exit Do 'Exit the wait loop
End If
Loop
Loop
Return
ponendo il pin c.3 (txrx_device) = 1 abiliti la parte di codice relativa alla trasmissione,
altrimenti avvi la parte relativa alla ricezione
Hai cambiato il fusibile CKDIV8? Se no allora l'oscillatore e' solo 1MHz.stò usando un atmega8535 a 8 Mhz (Oscillatore interno).
Hai cambiato il fusibile CKDIV8? Se no allora l'oscillatore e' solo 1MHz.
Riguardo il programma terminale: Hai connesso i pin Tx e RX (14 e 15) del Mega8535 al convertitore RS232 che esiste sul STK500?
Return to Microcontrollori e microprocessori
Users browsing this forum: No registered users and 2 guests