Skocz do zawartości

bluehais

Użytkownicy
  • Zawartość

    32
  • Rejestracja

  • Ostatnio

Reputacja

0 Neutralna

O bluehais

  • Ranga
    3/10

Informacje

  • Płeć
    Mężczyzna
  • Lokalizacja
    Lublin
  1. bluehais

    Problem z komunikacją Mega32 RF24L01+

    oczekuję by nadajnik wysyłał wartość zmiennej a odbiornik ją odbierał i wyświetlał na lcd Config Pinb.1 = Output 'CE pin is output Config Pinb.4 = Output 'SS pin is output Config Pinb.3 = Input 'IRQ pin is input między RF a uC dla nadajnika i i odbiornika jest: pin CE jest podłączony do PB.1 pin CSN jest podłączony do PB.4 pin IRQ jest podłączony do PB.3 działało mi to wcześniej po przeróbce oryginału (wywaliłem 1wire) ale teraz nie działa [ Dodano: 23-05-2016, 22:20 ] oryginał odbiornika: '/http://avrproject.ru '/2012 $regfile = "M8def.dat" $crystal = 16000000 $baud = 19200 $hwstack = 40 $swstack = 20 $framesize = 40 'ęîíôčăóđŕöč˙ äčńďëĺ˙ '=============================================================================================================== Config Lcdpin = Pin , Rs = Portc.0 , E = Portc.1 , Db4 = Portc.2 , Db5 = Portc.3 , Db6 = Portd.4 , Db7 = Portd.6 Config Lcd = 16 * 2 Cursor Off Cls '=============================================================================================================== '=== Declare sub routines Declare Sub R_register(byval Command As Byte , Byval C_bytes As Byte) Declare Sub W_register(byval C_bytes As Byte) '=== Constante === 'Define nRF24L01 interrupt flag's Const Idle_int = &H00 'Idle, no interrupt pending Const Max_rt = &H10 'Max #of Tx Retrans Interrupt Const Tx_ds = &H20 'Tx Data Sent Interrupt Const Rx_dr = &H40 'Rx Data Received 'SPI(nRF24L01) commands Const Read_reg = &H00 'Define Read Command To Register Const Write_reg = &H20 'Define Write Command To Register Const Rd_rx_pload = &H61 'Define Rx Payload Register Address Const Wr_tx_pload = &HA0 'Define Tx Payload Register Address Const Flush_tx = &HE1 'Define Flush Tx Register Command Const Flush_rx = &HE2 'Define Flush Rx Register Command Const Reuse_tx_pl = &HE3 'Define Reuse Tx Payload Register Command Const Nop_comm = &HFF 'Define No Operation , Might Be Used To Read Status Register 'SPI(nRF24L01) registers(addresses) Const Config_nrf = &H00 'Config' register address Const En_aa = &H01 'Enable Auto Acknowledgment' register address Const En_rxaddr = &H02 'Enabled RX addresses' register address Const Setup_aw = &H03 'Setup address width' register address Const Setup_retr = &H04 'Setup Auto. Retrans' register address Const Rf_ch = &H05 'RF channel' register address Const Rf_setup = &H06 'RF setup' register address Const Status = &H07 'Status' register address Const Observe_tx = &H08 'Observe TX' register address Const Cd = &H09 'Carrier Detect' register address Const Rx_addr_p0 = &H0A 'RX address pipe0' register address Const Rx_addr_p1 = &H0B 'RX address pipe1' register address Const Rx_addr_p2 = &H0C 'RX address pipe2' register address Const Rx_addr_p3 = &H0D 'RX address pipe3' register address Const Rx_addr_p4 = &H0E 'RX address pipe4' register address Const Rx_addr_p5 = &H0F 'RX address pipe5' register address Const Tx_addr = &H10 'TX address' register address Const Rx_pw_p0 = &H11 'RX payload width, pipe0' register address Const Rx_pw_p1 = &H12 'RX payload width, pipe1' register address Const Rx_pw_p2 = &H13 'RX payload width, pipe2' register address Const Rx_pw_p3 = &H14 'RX payload width, pipe3' register address Const Rx_pw_p4 = &H15 'RX payload width, pipe4' register address Const Rx_pw_p5 = &H16 'RX payload width, pipe5' register address Const Fifo_status = &H17 'FIFO Status Register' register address 'Various Const True = 1 Const False = 0 '=== 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 Config Pind.5 = Output 'CE pin is output Config Pinb.2 = Output 'SS pin is output Config Pind.7 = Input 'IRQ pin is input Ce Alias Portd.5 Ss Alias Portb.2 Irq Alias Pind.7 'ďîäęëţ÷ĺíčĺ ńâĺňîäčîäîâ číäčęŕöčč Config Portb.0 = Output Red_led Alias Portb.0 Red_led = 1 Waitms 20 Red_led = 0 Waitms 60 Red_led = 1 Waitms 20 Red_led = 0 Spiinit 'init the spi pins Set Ce Waitms 10 'Wait a moment until all hardware is stable Reset Ce 'Set CE pin low Reset Ss 'Set SS pin low (CSN pin) Dim D_bytes(33) As Byte , B_bytes(33) As Byte 'Dim the bytes use for SPI, D_bytes = outgoing B_bytes = Incoming Dim Temp As Byte , W As Word Dim Packet_count As Byte Goto Main_rx Main_rx: Print "Receiver rady!" Print "" Lcd "NRF24L01+DS18B20" Lowerline Lcd "AVRproject.ru" Wait 2 Call R_register(status , 1) 'Read STATUS register 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 'Ĺńëč íŕ âűâîäĺ IRQ íčçęčé óđîâĺíü â áóôĺđ ďđčĺěíčęŕ ÷ňî-ňî ďîďŕëî Red_led = 1 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 "Temperature: " ; Hex(b_bytes(1)) ; Hex(b_bytes(2)) ; Hex(b_bytes(3)) ; Hex(b_bytes(4)) ; Hex(b_bytes(5)) 'Print the pload Cls Lcd "NRF24L01+DS18B20" Lowerline Lcd "T: " ; B_bytes(1) ; "C" 'ňĺěďĺđŕňóđŕ 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 Red_led = 0 Loop Return '=== Sub routines === Sub W_register(byval C_bytes As Byte) 'Write register with SPI Reset Ss 'Manual control SS pin, set SS low before shifting out the bytes Spiout D_bytes(1) , C_bytes 'Shiftout the data bytes trough SPI , C_bytes is the amount bytes to be written Set Ss 'Set SS high End Sub Sub R_register(byval Command As Byte , Byval C_bytes As Byte) As Byte 'C_bytes = Count_bytes, number off bytes to be read Reset Ss 'Manual controle SS pin, set low before shifting in/out the bytes Spiout Command , 1 'First shiftout the register to be read Spiin B_bytes(1) , C_bytes 'Read back the bytes from SPI sended by nRF20L01 Set Ss 'Set SS back to high level End Sub Setup_rx: 'Setup for RX D_bytes(1) = Write_reg + Rx_addr_p0 'RX adress for pipe0 D_bytes(2) = &H34 D_bytes(3) = &H43 D_bytes(4) = &H10 D_bytes(5) = &H10 D_bytes(6) = &H01 Call W_register(6) 'Send 6 bytes to SPI D_bytes(1) = Write_reg + En_aa 'Enable auto ACK for pipe0 D_bytes(2) = &H01 Call W_register(2) D_bytes(1) = Write_reg + En_rxaddr 'Enable RX adress for pipe0 D_bytes(2) = &H01 Call W_register(2) D_bytes(1) = Write_reg + Rf_ch 'Set RF channel D_bytes(2) = 40 Call W_register(2) D_bytes(1) = Write_reg + Rx_pw_p0 'Set RX pload width for pipe0 D_bytes(2) = 5 Call W_register(2) D_bytes(1) = Write_reg + Rf_setup 'Setup RF-> Output power 0dbm, datarate 2Mbps and LNA gain on D_bytes(2) = &H0F Call W_register(2) D_bytes(1) = Write_reg + Config_nrf 'Setup CONFIG-> PRX=1(RX_device), PWR_UP=1, CRC 2bytes, Enable CRC D_bytes(2) = &H0F Call W_register(2) Return Dump_registers: 'Dumps all nRF24L01 registers to the terminal, handy for debugging Print "* Dump nRF24L01 Registers *" Call R_register(config_nrf , 1) Print "CONFIG : " ; Bin(b_bytes(1)) Call R_register(en_aa , 1) Print "EN_AA : " ; Bin(b_bytes(1)) Call R_register(en_rxaddr , 1) Print "EN_RXADDR : " ; Bin(b_bytes(1)) Call R_register(setup_aw , 1) Print "SETUP_AW : " ; Bin(b_bytes(1)) Call R_register(setup_retr , 1) Print "SETUP_RETR : " ; Bin(b_bytes(1)) Call R_register(rf_ch , 1) Print "RF_CH : " ; B_bytes(1) Call R_register(rf_setup , 1) Print "RF_SETUP : " ; Bin(b_bytes(1)) Call R_register(status , 1) Print "STATUS : " ; Bin(b_bytes(1)) Call R_register(observe_tx , 1) Print "OBSERVE_TX : " ; Bin(b_bytes(1)) Call R_register(cd , 1) Print "CD : " ; Bin(b_bytes(1)) Call R_register(rx_addr_p0 , 5) Print "RX_ADDR_P0 : " ; Hex(b_bytes(1)) ; Hex(b_bytes(2)) ; Hex(b_bytes(3)) ; Hex(b_bytes(4)) ; Hex(b_bytes(5)) Call R_register(rx_addr_p1 , 5) Print "RX_ADDR_P1 : " ; Hex(b_bytes(1)) ; Hex(b_bytes(2)) ; Hex(b_bytes(3)) ; Hex(b_bytes(4)) ; Hex(b_bytes(5)) Call R_register(rx_addr_p2 , 5) Print "RX_ADDR_P2 : " ; Hex(b_bytes(1)) ; Hex(b_bytes(2)) ; Hex(b_bytes(3)) ; Hex(b_bytes(4)) ; Hex(b_bytes(5)) Call R_register(rx_addr_p3 , 5) Print "RX_ADDR_P3 : " ; Hex(b_bytes(1)) ; Hex(b_bytes(2)) ; Hex(b_bytes(3)) ; Hex(b_bytes(4)) ; Hex(b_bytes(5)) Call R_register(rx_addr_p4 , 5) Print "RX_ADDR_P4 : " ; Hex(b_bytes(1)) ; Hex(b_bytes(2)) ; Hex(b_bytes(3)) ; Hex(b_bytes(4)) ; Hex(b_bytes(5)) Call R_register(rx_addr_p5 , 5) Print "RX_ADDR_P5 : " ; Hex(b_bytes(1)) ; Hex(b_bytes(2)) ; Hex(b_bytes(3)) ; Hex(b_bytes(4)) ; Hex(b_bytes(5)) Call R_register(tx_addr , 5) Print "TX_ADDR : " ; Hex(b_bytes(1)) ; Hex(b_bytes(2)) ; Hex(b_bytes(3)) ; Hex(b_bytes(4)) ; Hex(b_bytes(5)) Call R_register(rx_pw_p0 , 5) Print "RX_PW_P0 : " ; Hex(b_bytes(1)) ; Hex(b_bytes(2)) ; Hex(b_bytes(3)) ; Hex(b_bytes(4)) ; Hex(b_bytes(5)) Call R_register(rx_pw_p1 , 5) Print "RX_PW_P1 : " ; Hex(b_bytes(1)) ; Hex(b_bytes(2)) ; Hex(b_bytes(3)) ; Hex(b_bytes(4)) ; Hex(b_bytes(5)) Call R_register(rx_pw_p2 , 5) Print "RX_PW_P2 : " ; Hex(b_bytes(1)) ; Hex(b_bytes(2)) ; Hex(b_bytes(3)) ; Hex(b_bytes(4)) ; Hex(b_bytes(5)) Call R_register(rx_pw_p3 , 5) Print "RX_PW_P3 : " ; Hex(b_bytes(1)) ; Hex(b_bytes(2)) ; Hex(b_bytes(3)) ; Hex(b_bytes(4)) ; Hex(b_bytes(5)) Call R_register(rx_pw_p4 , 5) Print "RX_PW_P4 : " ; Hex(b_bytes(1)) ; Hex(b_bytes(2)) ; Hex(b_bytes(3)) ; Hex(b_bytes(4)) ; Hex(b_bytes(5)) Call R_register(rx_pw_p5 , 5) Print "RX_PW_P5 : " ; Hex(b_bytes(1)) ; Hex(b_bytes(2)) ; Hex(b_bytes(3)) ; Hex(b_bytes(4)) ; Hex(b_bytes(5)) Call R_register(fifo_status , 1) Print "FIFO_STATUS : " ; Bin(b_bytes(1)) Return oryginał nadajnika '/http://avrproject.ru '/2012 $regfile = "M8def.dat" $crystal = 16000000 $baud = 19200 $hwstack = 40 $swstack = 20 $framesize = 40 '=== Declare sub routines Declare Sub R_register(byval Command As Byte , Byval C_bytes As Byte) Declare Sub W_register(byval C_bytes As Byte) '=== Constante === 'Define nRF24L01 interrupt flag's Const Idle_int = &H00 'Idle, no interrupt pending Const Max_rt = &H10 'Max #of Tx Retrans Interrupt Const Tx_ds = &H20 'Tx Data Sent Interrupt Const Rx_dr = &H40 'Rx Data Received 'SPI(nRF24L01) commands Const Read_reg = &H00 'Define Read Command To Register Const Write_reg = &H20 'Define Write Command To Register Const Rd_rx_pload = &H61 'Define Rx Payload Register Address Const Wr_tx_pload = &HA0 'Define Tx Payload Register Address Const Flush_tx = &HE1 'Define Flush Tx Register Command Const Flush_rx = &HE2 'Define Flush Rx Register Command Const Reuse_tx_pl = &HE3 'Define Reuse Tx Payload Register Command Const Nop_comm = &HFF 'Define No Operation , Might Be Used To Read Status Register 'SPI(nRF24L01) registers(addresses) Const Config_nrf = &H00 'Config' register address Const En_aa = &H01 'Enable Auto Acknowledgment' register address Const En_rxaddr = &H02 'Enabled RX addresses' register address Const Setup_aw = &H03 'Setup address width' register address Const Setup_retr = &H04 'Setup Auto. Retrans' register address Const Rf_ch = &H05 'RF channel' register address Const Rf_setup = &H06 'RF setup' register address Const Status = &H07 'Status' register address Const Observe_tx = &H08 'Observe TX' register address Const Cd = &H09 'Carrier Detect' register address Const Rx_addr_p0 = &H0A 'RX address pipe0' register address Const Rx_addr_p1 = &H0B 'RX address pipe1' register address Const Rx_addr_p2 = &H0C 'RX address pipe2' register address Const Rx_addr_p3 = &H0D 'RX address pipe3' register address Const Rx_addr_p4 = &H0E 'RX address pipe4' register address Const Rx_addr_p5 = &H0F 'RX address pipe5' register address Const Tx_addr = &H10 'TX address' register address Const Rx_pw_p0 = &H11 'RX payload width, pipe0' register address Const Rx_pw_p1 = &H12 'RX payload width, pipe1' register address Const Rx_pw_p2 = &H13 'RX payload width, pipe2' register address Const Rx_pw_p3 = &H14 'RX payload width, pipe3' register address Const Rx_pw_p4 = &H15 'RX payload width, pipe4' register address Const Rx_pw_p5 = &H16 'RX payload width, pipe5' register address Const Fifo_status = &H17 'FIFO Status Register' register address Dim D_bytes(33) As Byte , B_bytes(33) As Byte 'Dim the bytes use for SPI, D_bytes = outgoing B_bytes = Incoming Dim Temp As Byte , W As Word Dim Packet_count As Byte '=== Config hardware === Config Spi = Hard , Interrupt = Off , Data Order = Msb , Master = Yes , Polarity = Low , Phase = 0 , Clockrate = 16 , Noss = 1 'Software SPI is NOT working with the nRF24L01, use hardware SPI only, but the SS pin must be controlled by our self Config Pind.5 = Output 'CE pin is output Config Pinb.2 = Output 'SS pin is output Config Pind.7 = Input 'IRQ pin is input Ce Alias Portd.5 Ss Alias Portb.2 Irq Alias Pind.7 'ďîäęëţ÷ĺíčĺ ńâĺňîäčîäîâ číäčęŕöčč Config Portd.3 = Output Config Portd.4 = Output Red_led Alias Portd.3 Green_led Alias Portd.4 'ďîäęëţ÷ĺíčĺ äŕň÷čęŕ '==================================================================================== Config 1wire = Portc.0 Dim Byte0 As Byte Dim Byte1 As Byte Dim Sign As String * 1 Dim T As Byte Dim T1 As Byte Dim T2 As Byte '================================================================================== Red_led = 1 Green_led = 1 Waitms 20 Red_led = 0 Green_led = 0 Waitms 60 Red_led = 1 Green_led = 1 Waitms 20 Red_led = 0 Green_led = 0 Spiinit 'init the spi pins Set Ce Waitms 10 'Wait a moment until all hardware is stable Reset Ce 'Set CE pin low Reset Ss 'Set SS pin low (CSN pin) Print "TX_device" 'Send to terminal who i'm Red_led = 1 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) = &B00110000 Call W_register(2) Red_led = 0 Do '============================================================================== 'ďîäăîňîâęŕ äŕííűő 'îďđîń äŕň÷čęŕ Gosub 18b20 '============================================================================== 'Main loop for TX Green_led = 1 Incr Packet_count 'Increase the send packet counter, for test only If Packet_count > 254 Then Packet_count = 0 Gosub Setup_tx 'Setup the nrf24l01 for TX D_bytes(1) = Wr_tx_pload 'Put 5 bytes in the TX pload buffer D_bytes(2) = T1 'Byte 1 - îňďđŕâë˙ĺěŕ˙ ňĺěďĺđŕňóđŕ D_bytes(3) = &HBB 'Byte 2 - îńňŕëüíűĺ 4 áŕéňŕ ěîćíî ňŕęćĺ čńďîëüçîâŕňü â ńâîčő öĺë˙ő D_bytes(4) = &HCC 'Byte 3 D_bytes(5) = &H11 'Byte 4 D_bytes(6) = Packet_count 'Byte 5 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 Red_led = 1 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, Flushing 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) Waitms 10 Red_led = 0 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) Waitms 10 Red_led = 0 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 > 200 Then 'Waited for 200ms Print "No irq response from RF24L01 within 100ms" Exit Do 'Exit the wait loop End If Loop Red_led = 0 Wait 1 Loop '=== Sub routines === Sub W_register(byval C_bytes As Byte) 'Write register with SPI Reset Ss 'Manual control SS pin, set SS low before shifting out the bytes Spiout D_bytes(1) , C_bytes 'Shiftout the data bytes trough SPI , C_bytes is the amount bytes to be written Set Ss 'Set SS high End Sub Sub R_register(byval Command As Byte , Byval C_bytes As Byte) As Byte 'C_bytes = Count_bytes, number off bytes to be read Reset Ss 'Manual controle SS pin, set low before shifting in/out the bytes Spiout Command , 1 'First shiftout the register to be read Spiin B_bytes(1) , C_bytes 'Read back the bytes from SPI sended by nRF20L01 Set Ss 'Set SS back to high level End Sub Setup_tx: 'Setup for TX D_bytes(1) = Write_reg + Tx_addr 'TX adress D_bytes(2) = &H34 D_bytes(3) = &H43 D_bytes(4) = &H10 D_bytes(5) = &H10 D_bytes(6) = &H01 Call W_register(6) D_bytes(1) = Write_reg + Rx_addr_p0 'RX adress for pipe0 D_bytes(2) = &H34 D_bytes(3) = &H43 D_bytes(4) = &H10 D_bytes(5) = &H10 D_bytes(6) = &H01 Call W_register(6) D_bytes(1) = Write_reg + En_aa 'Enable auto ACK for pipe0 D_bytes(2) = &H01 Call W_register(2) D_bytes(1) = Write_reg + En_rxaddr 'Enable RX adress for pipe0 D_bytes(2) = &H01 Call W_register(2) D_bytes(1) = Write_reg + Rf_ch 'Set RF channel D_bytes(2) = 40 Call W_register(2) D_bytes(1) = Write_reg + Rf_setup 'Setup RF-> Output power 0dbm, datarate 2Mbps and LNA gain on D_bytes(2) = &H0F Call W_register(2) D_bytes(1) = Write_reg + Config_nrf 'Setup CONFIG-> PRX=0(TX_device), PWR_UP=1, CRC 2bytes, Enable CRC D_bytes(2) = &H0E Call W_register(2) Return 'îďđîń äŕň÷čęŕ '===================================================================== 18b20: 1wreset If Err = 1 Then 'ĺńëč ďđč îďđîńĺ íĺáűëî îňâĺňŕ ńňŕâčě ôëŕă îřčáęč Red_led = 1 Wait 5 Else ' číŕ÷ĺ, ĺńëč îřčáęč íĺ áűëî, ďđîäîëćŕĺě îďđîń äŕň÷čęŕ 1wwrite &HCC ' Âűäŕĺě ęîěŕíäó ÷ňĺíč˙ ĎÇÓ 1wwrite &H44 ' Çŕďóńę čçěĺđĺíč˙ Waitms 750 ' Ćäĺě îęîí÷ŕíč˙ ďđĺîáđŕçîâŕíč˙ 1wreset 1wwrite &HCC 1wwrite &HBE ' Ęîěŕíäŕ ÷ňĺíč˙ ÎÇÓ äŕň÷čęŕ Byte0 = 1wread() ' ×čňŕĺě íóëĺâîé áŕéň Byte1 = 1wread() ' ×čňŕĺě ďĺđâűé áŕéň If Byte1 > 248 Then ' Ďđîâĺđęŕ íŕ îňđčöŕňĺëüíîńňü ňĺěďĺđŕňóđű Byte0 = &HFF - Byte0 Byte1 = &HFF - Byte1 Sign = "-" Else Sign = "+" End If T1 = Byte0 / 16 ' Ńäâčăŕĺě íóëĺâîé áŕéň âďđŕâî íŕ 4 áčňŕ (2*2*2*2=16) T2 = Byte1 * 16 ' Ńäâčăŕĺě ďĺđâűé áŕéň âëĺâî íŕ 4 áčňŕ (2*2*2*2=16) T1 = T1 + T2 ' Ôîđěčđóĺě đĺçóëüňŕň äë˙ âűâîäŕ íŕ äčńďëĺé ' *** Ęîđđĺęöč˙ ďîëó÷ĺííűő çíŕ÷ĺíčé If Sign = "-" Then ' äë˙ ęîđđĺęňíîăî âűâîäŕ îňđčöŕňĺëüíűő ňĺěďĺđŕňóđ T1 = T1 + 1 End If If Sign = "+" And T1 = 0 Then ' óáčđŕĺě çíŕę "+" ń íóëĺâîé ňĺěďĺđŕňóđű Sign = " " End If End If Return Chcę po prostu wysyłać wartość zmiennej z nadajnika do odbiornika i wyświetlać jej wartość tyle że u mnie nie potrzebne jest 1wire i ten odczyt z czujnika 18b20.
  2. Witam, Mam sobie nadajnik i odbiornik i kod dla nadajnika: '/http://avrproject.ru '/2012 $regfile = "m32def.dat" $crystal = 12000000 $baud = 19200 $hwstack = 40 $swstack = 20 $framesize = 40 Config Adc = Single , Prescaler = Auto , Reference = Avcc '=== Declare sub routines Declare Sub R_register(byval Command As Byte , Byval C_bytes As Byte) Declare Sub W_register(byval C_bytes As Byte) '=== Constante === 'Define nRF24L01 interrupt flag's Const Idle_int = &H00 'Idle, no interrupt pending Const Max_rt = &H10 'Max #of Tx Retrans Interrupt Const Tx_ds = &H20 'Tx Data Sent Interrupt Const Rx_dr = &H40 'Rx Data Received 'SPI(nRF24L01) commands Const Read_reg = &H00 'Define Read Command To Register Const Write_reg = &H20 'Define Write Command To Register Const Rd_rx_pload = &H61 'Define Rx Payload Register Address Const Wr_tx_pload = &HA0 'Define Tx Payload Register Address Const Flush_tx = &HE1 'Define Flush Tx Register Command Const Flush_rx = &HE2 'Define Flush Rx Register Command Const Reuse_tx_pl = &HE3 'Define Reuse Tx Payload Register Command Const Nop_comm = &HFF 'Define No Operation , Might Be Used To Read Status Register 'SPI(nRF24L01) registers(addresses) Const Config_nrf = &H00 'Config' register address Const En_aa = &H01 'Enable Auto Acknowledgment' register address Const En_rxaddr = &H02 'Enabled RX addresses' register address Const Setup_aw = &H03 'Setup address width' register address Const Setup_retr = &H04 'Setup Auto. Retrans' register address Const Rf_ch = &H05 'RF channel' register address Const Rf_setup = &H06 'RF setup' register address Const Status = &H07 'Status' register address Const Observe_tx = &H08 'Observe TX' register address Const Cd = &H09 'Carrier Detect' register address Const Rx_addr_p0 = &H0A 'RX address pipe0' register address Const Rx_addr_p1 = &H0B 'RX address pipe1' register address Const Rx_addr_p2 = &H0C 'RX address pipe2' register address Const Rx_addr_p3 = &H0D 'RX address pipe3' register address Const Rx_addr_p4 = &H0E 'RX address pipe4' register address Const Rx_addr_p5 = &H0F 'RX address pipe5' register address Const Tx_addr = &H10 'TX address' register address Const Rx_pw_p0 = &H11 'RX payload width, pipe0' register address Const Rx_pw_p1 = &H12 'RX payload width, pipe1' register address Const Rx_pw_p2 = &H13 'RX payload width, pipe2' register address Const Rx_pw_p3 = &H14 'RX payload width, pipe3' register address Const Rx_pw_p4 = &H15 'RX payload width, pipe4' register address Const Rx_pw_p5 = &H16 'RX payload width, pipe5' register address Const Fifo_status = &H17 'FIFO Status Register' register address Dim D_bytes(33) As Byte , B_bytes(33) As Byte 'Dim the bytes use for SPI, D_bytes = outgoing B_bytes = Incoming Dim Temp As Byte , W As Word Dim Packet_count As Byte '=== Config hardware === Config Spi = Hard , Interrupt = Off , Data Order = Msb , Master = Yes , Polarity = Low , Phase = 0 , Clockrate = 16 , Noss = 1 'Software SPI is NOT working with the nRF24L01, use hardware SPI only, but the SS pin must be controlled by our self Config Pinb.1 = Output 'CE pin is output Config Pinb.4 = Output 'SS pin is output Config Pinb.3 = Input 'IRQ pin is input Ce Alias Portb.1 Ss Alias Portb.4 Irq Alias Pinb.3 'ďîäęëţ÷ĺíčĺ ńâĺňîäčîäîâ číäčęŕöčč Config Portd.5 = Output Config Portd.6 = Output Red_led Alias Portd.5 Green_led Alias Portd.6 Dim Byte0 As Byte Dim Byte1 As Byte Dim Sign As String * 1 Dim T As Byte Dim T1 As Byte Dim T2 As Byte '================================================================================== Red_led = 1 Green_led = 1 Waitms 20 Red_led = 0 Green_led = 0 Waitms 60 Red_led = 1 Green_led = 1 Waitms 20 Red_led = 0 Green_led = 0 Spiinit 'init the spi pins Set Ce Waitms 10 'Wait a moment until all hardware is stable Reset Ce 'Set CE pin low Reset Ss 'Set SS pin low (CSN pin) Print "TX_device" 'Send to terminal who i'm Red_led = 1 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) = &B00110000 Call W_register(2) Red_led = 0 Do 'Main loop for TX Green_led = 1 Incr Packet_count 'Increase the send packet counter, for test only If Packet_count > 254 Then Packet_count = 0 Gosub Setup_tx 'Setup the nrf24l01 for TX D_bytes(1) = Wr_tx_pload 'Put 5 bytes in the TX pload buffer D_bytes(2) = T1 'Byte 1 - îňďđŕâë˙ĺěŕ˙ ňĺěďĺđŕňóđŕ D_bytes(3) = &HBB 'Byte 2 - îńňŕëüíűĺ 4 áŕéňŕ ěîćíî ňŕęćĺ čńďîëüçîâŕňü â ńâîčő öĺë˙ő D_bytes(4) = &HCC 'Byte 3 D_bytes(5) = &H11 'Byte 4 D_bytes(6) = Packet_count 'Byte 5 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 Red_led = 1 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, Flushing 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) Waitms 10 Red_led = 0 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) Waitms 10 Red_led = 0 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 > 200 Then 'Waited for 200ms Print "No irq response from RF24L01 within 100ms" Exit Do 'Exit the wait loop End If Loop Loop '=== Sub routines === Sub W_register(byval C_bytes As Byte) 'Write register with SPI Reset Ss 'Manual control SS pin, set SS low before shifting out the bytes Spiout D_bytes(1) , C_bytes 'Shiftout the data bytes trough SPI , C_bytes is the amount bytes to be written Set Ss 'Set SS high End Sub Sub R_register(byval Command As Byte , Byval C_bytes As Byte) As Byte 'C_bytes = Count_bytes, number off bytes to be read Reset Ss 'Manual controle SS pin, set low before shifting in/out the bytes Spiout Command , 1 'First shiftout the register to be read Spiin B_bytes(1) , C_bytes 'Read back the bytes from SPI sended by nRF20L01 Set Ss 'Set SS back to high level End Sub Setup_tx: 'Setup for TX D_bytes(1) = Write_reg + Tx_addr 'TX adress D_bytes(2) = &H34 D_bytes(3) = &H43 D_bytes(4) = &H10 D_bytes(5) = &H10 D_bytes(6) = &H01 Call W_register(6) D_bytes(1) = Write_reg + Rx_addr_p0 'RX adress for pipe0 D_bytes(2) = &H34 D_bytes(3) = &H43 D_bytes(4) = &H10 D_bytes(5) = &H10 D_bytes(6) = &H01 Call W_register(6) D_bytes(1) = Write_reg + En_aa 'Enable auto ACK for pipe0 D_bytes(2) = &H01 Call W_register(2) D_bytes(1) = Write_reg + En_rxaddr 'Enable RX adress for pipe0 D_bytes(2) = &H01 Call W_register(2) D_bytes(1) = Write_reg + Rf_ch 'Set RF channel D_bytes(2) = 40 Call W_register(2) D_bytes(1) = Write_reg + Rf_setup 'Setup RF-> Output power 0dbm, datarate 2Mbps and LNA gain on D_bytes(2) = &H0F Call W_register(2) D_bytes(1) = Write_reg + Config_nrf 'Setup CONFIG-> PRX=0(TX_device), PWR_UP=1, CRC 2bytes, Enable CRC D_bytes(2) = &H0E Call W_register(2) Return i kod odbiornika: '/http://avrproject.ru '/2012 $regfile = "m16def.dat" $crystal = 12000000 $baud = 19200 $hwstack = 40 $swstack = 20 $framesize = 40 'ęîíôčăóđŕöč˙ äčńďëĺ˙ '=============================================================================================================== Config Lcdpin = Pin , Rs = Portc.0 , E = Portc.1 , Db4 = Portc.2 , Db5 = Portc.3 , Db6 = Portc.4 , Db7 = Portc.5 Config Lcd = 16 * 2 Cursor Off Cls '=============================================================================================================== '=== Declare sub routines Declare Sub R_register(byval Command As Byte , Byval C_bytes As Byte) Declare Sub W_register(byval C_bytes As Byte) '=== Constante === 'Define nRF24L01 interrupt flag's Const Idle_int = &H00 'Idle, no interrupt pending Const Max_rt = &H10 'Max #of Tx Retrans Interrupt Const Tx_ds = &H20 'Tx Data Sent Interrupt Const Rx_dr = &H40 'Rx Data Received 'SPI(nRF24L01) commands Const Read_reg = &H00 'Define Read Command To Register Const Write_reg = &H20 'Define Write Command To Register Const Rd_rx_pload = &H61 'Define Rx Payload Register Address Const Wr_tx_pload = &HA0 'Define Tx Payload Register Address Const Flush_tx = &HE1 'Define Flush Tx Register Command Const Flush_rx = &HE2 'Define Flush Rx Register Command Const Reuse_tx_pl = &HE3 'Define Reuse Tx Payload Register Command Const Nop_comm = &HFF 'Define No Operation , Might Be Used To Read Status Register 'SPI(nRF24L01) registers(addresses) Const Config_nrf = &H00 'Config' register address Const En_aa = &H01 'Enable Auto Acknowledgment' register address Const En_rxaddr = &H02 'Enabled RX addresses' register address Const Setup_aw = &H03 'Setup address width' register address Const Setup_retr = &H04 'Setup Auto. Retrans' register address Const Rf_ch = &H05 'RF channel' register address Const Rf_setup = &H06 'RF setup' register address Const Status = &H07 'Status' register address Const Observe_tx = &H08 'Observe TX' register address Const Cd = &H09 'Carrier Detect' register address Const Rx_addr_p0 = &H0A 'RX address pipe0' register address Const Rx_addr_p1 = &H0B 'RX address pipe1' register address Const Rx_addr_p2 = &H0C 'RX address pipe2' register address Const Rx_addr_p3 = &H0D 'RX address pipe3' register address Const Rx_addr_p4 = &H0E 'RX address pipe4' register address Const Rx_addr_p5 = &H0F 'RX address pipe5' register address Const Tx_addr = &H10 'TX address' register address Const Rx_pw_p0 = &H11 'RX payload width, pipe0' register address Const Rx_pw_p1 = &H12 'RX payload width, pipe1' register address Const Rx_pw_p2 = &H13 'RX payload width, pipe2' register address Const Rx_pw_p3 = &H14 'RX payload width, pipe3' register address Const Rx_pw_p4 = &H15 'RX payload width, pipe4' register address Const Rx_pw_p5 = &H16 'RX payload width, pipe5' register address Const Fifo_status = &H17 'FIFO Status Register' register address 'Various Const True = 1 Const False = 0 '=== 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 Config Pinb.1 = Output 'CE pin is output Config Pinb.4 = Output 'SS pin is output Config Pinb.3 = Input 'IRQ pin is input Ce Alias Portb.1 Ss Alias Portb.4 Irq Alias Pinb.3 'ďîäęëţ÷ĺíčĺ ńâĺňîäčîäîâ číäčęŕöčč Config Portb.0 = Output Red_led Alias Portb.0 Red_led = 1 Waitms 20 Red_led = 0 Waitms 60 Red_led = 1 Waitms 20 Red_led = 0 Spiinit 'init the spi pins Set Ce Waitms 10 'Wait a moment until all hardware is stable Reset Ce 'Set CE pin low Reset Ss 'Set SS pin low (CSN pin) Dim D_bytes(33) As Byte , B_bytes(33) As Byte 'Dim the bytes use for SPI, D_bytes = outgoing B_bytes = Incoming Dim Temp As Byte , W As Word Dim Packet_count As Byte Goto Main_rx Main_rx: Print "Receiver rady!" Print "" Lcd "NRF24L01+DS18B20" Lowerline Lcd "AVRproject.ru" Wait 2 Call R_register(status , 1) 'Read STATUS register 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 'Ĺńëč íŕ âűâîäĺ IRQ íčçęčé óđîâĺíü â áóôĺđ ďđčĺěíčęŕ ÷ňî-ňî ďîďŕëî Red_led = 1 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 "Temperature: " ; Hex(b_bytes(1)) ; Hex(b_bytes(2)) ; Hex(b_bytes(3)) ; Hex(b_bytes(4)) ; Hex(b_bytes(5)) 'Print the pload Cls Lcd "NRF24L01+DS18B20" Lowerline Lcd "T: " ; B_bytes(1) ; "C" 'ňĺěďĺđŕňóđŕ 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 Red_led = 0 Loop Return '=== Sub routines === Sub W_register(byval C_bytes As Byte) 'Write register with SPI Reset Ss 'Manual control SS pin, set SS low before shifting out the bytes Spiout D_bytes(1) , C_bytes 'Shiftout the data bytes trough SPI , C_bytes is the amount bytes to be written Set Ss 'Set SS high End Sub Sub R_register(byval Command As Byte , Byval C_bytes As Byte) As Byte 'C_bytes = Count_bytes, number off bytes to be read Reset Ss 'Manual controle SS pin, set low before shifting in/out the bytes Spiout Command , 1 'First shiftout the register to be read Spiin B_bytes(1) , C_bytes 'Read back the bytes from SPI sended by nRF20L01 Set Ss 'Set SS back to high level End Sub Setup_rx: 'Setup for RX D_bytes(1) = Write_reg + Rx_addr_p0 'RX adress for pipe0 D_bytes(2) = &H34 D_bytes(3) = &H43 D_bytes(4) = &H10 D_bytes(5) = &H10 D_bytes(6) = &H01 Call W_register(6) 'Send 6 bytes to SPI D_bytes(1) = Write_reg + En_aa 'Enable auto ACK for pipe0 D_bytes(2) = &H01 Call W_register(2) D_bytes(1) = Write_reg + En_rxaddr 'Enable RX adress for pipe0 D_bytes(2) = &H01 Call W_register(2) D_bytes(1) = Write_reg + Rf_ch 'Set RF channel D_bytes(2) = 40 Call W_register(2) D_bytes(1) = Write_reg + Rx_pw_p0 'Set RX pload width for pipe0 D_bytes(2) = 5 Call W_register(2) D_bytes(1) = Write_reg + Rf_setup 'Setup RF-> Output power 0dbm, datarate 2Mbps and LNA gain on D_bytes(2) = &H0F Call W_register(2) D_bytes(1) = Write_reg + Config_nrf 'Setup CONFIG-> PRX=1(RX_device), PWR_UP=1, CRC 2bytes, Enable CRC D_bytes(2) = &H0F Call W_register(2) Return Dump_registers: 'Dumps all nRF24L01 registers to the terminal, handy for debugging Print "* Dump nRF24L01 Registers *" Call R_register(config_nrf , 1) Print "CONFIG : " ; Bin(b_bytes(1)) Call R_register(en_aa , 1) Print "EN_AA : " ; Bin(b_bytes(1)) Call R_register(en_rxaddr , 1) Print "EN_RXADDR : " ; Bin(b_bytes(1)) Call R_register(setup_aw , 1) Print "SETUP_AW : " ; Bin(b_bytes(1)) Call R_register(setup_retr , 1) Print "SETUP_RETR : " ; Bin(b_bytes(1)) Call R_register(rf_ch , 1) Print "RF_CH : " ; B_bytes(1) Call R_register(rf_setup , 1) Print "RF_SETUP : " ; Bin(b_bytes(1)) Call R_register(status , 1) Print "STATUS : " ; Bin(b_bytes(1)) Call R_register(observe_tx , 1) Print "OBSERVE_TX : " ; Bin(b_bytes(1)) Call R_register(cd , 1) Print "CD : " ; Bin(b_bytes(1)) Call R_register(rx_addr_p0 , 5) Print "RX_ADDR_P0 : " ; Hex(b_bytes(1)) ; Hex(b_bytes(2)) ; Hex(b_bytes(3)) ; Hex(b_bytes(4)) ; Hex(b_bytes(5)) Call R_register(rx_addr_p1 , 5) Print "RX_ADDR_P1 : " ; Hex(b_bytes(1)) ; Hex(b_bytes(2)) ; Hex(b_bytes(3)) ; Hex(b_bytes(4)) ; Hex(b_bytes(5)) Call R_register(rx_addr_p2 , 5) Print "RX_ADDR_P2 : " ; Hex(b_bytes(1)) ; Hex(b_bytes(2)) ; Hex(b_bytes(3)) ; Hex(b_bytes(4)) ; Hex(b_bytes(5)) Call R_register(rx_addr_p3 , 5) Print "RX_ADDR_P3 : " ; Hex(b_bytes(1)) ; Hex(b_bytes(2)) ; Hex(b_bytes(3)) ; Hex(b_bytes(4)) ; Hex(b_bytes(5)) Call R_register(rx_addr_p4 , 5) Print "RX_ADDR_P4 : " ; Hex(b_bytes(1)) ; Hex(b_bytes(2)) ; Hex(b_bytes(3)) ; Hex(b_bytes(4)) ; Hex(b_bytes(5)) Call R_register(rx_addr_p5 , 5) Print "RX_ADDR_P5 : " ; Hex(b_bytes(1)) ; Hex(b_bytes(2)) ; Hex(b_bytes(3)) ; Hex(b_bytes(4)) ; Hex(b_bytes(5)) Call R_register(tx_addr , 5) Print "TX_ADDR : " ; Hex(b_bytes(1)) ; Hex(b_bytes(2)) ; Hex(b_bytes(3)) ; Hex(b_bytes(4)) ; Hex(b_bytes(5)) Call R_register(rx_pw_p0 , 5) Print "RX_PW_P0 : " ; Hex(b_bytes(1)) ; Hex(b_bytes(2)) ; Hex(b_bytes(3)) ; Hex(b_bytes(4)) ; Hex(b_bytes(5)) Call R_register(rx_pw_p1 , 5) Print "RX_PW_P1 : " ; Hex(b_bytes(1)) ; Hex(b_bytes(2)) ; Hex(b_bytes(3)) ; Hex(b_bytes(4)) ; Hex(b_bytes(5)) Call R_register(rx_pw_p2 , 5) Print "RX_PW_P2 : " ; Hex(b_bytes(1)) ; Hex(b_bytes(2)) ; Hex(b_bytes(3)) ; Hex(b_bytes(4)) ; Hex(b_bytes(5)) Call R_register(rx_pw_p3 , 5) Print "RX_PW_P3 : " ; Hex(b_bytes(1)) ; Hex(b_bytes(2)) ; Hex(b_bytes(3)) ; Hex(b_bytes(4)) ; Hex(b_bytes(5)) Call R_register(rx_pw_p4 , 5) Print "RX_PW_P4 : " ; Hex(b_bytes(1)) ; Hex(b_bytes(2)) ; Hex(b_bytes(3)) ; Hex(b_bytes(4)) ; Hex(b_bytes(5)) Call R_register(rx_pw_p5 , 5) Print "RX_PW_P5 : " ; Hex(b_bytes(1)) ; Hex(b_bytes(2)) ; Hex(b_bytes(3)) ; Hex(b_bytes(4)) ; Hex(b_bytes(5)) Call R_register(fifo_status , 1) Print "FIFO_STATUS : " ; Bin(b_bytes(1)) Return Nie ma między nimi komunikacji. Gdzie może być błąd?
  3. Przeanalizowałem kod Trekera i w głowie mi się trochę pomieszało (za dużo zmiennych) Nie wiem czy mój tok rozumowania jest dobry ale napisałem coś takiego: $regfile = "m8def.dat" $crystal = 8000000 Config Timer1 = Pwm , Pwm = 8 , Prescale = 1 , Compare A Pwm = Clear Down , Compare B Pwm = Clear Down Config Adc = Single , Prescaler = Auto 'adc startuje ;) Start Adc 'konfiguracja portow Config Portd = Output Config Portb = Output 'do mostka Silnik_lewy_a Alias Portd.0 Silnik_lewy_b Alias Portd.1 Silnik_prawy_a Alias Portd.2 Silnik_prawy_b Alias Portd.3 Dioda Alias Portd.4 'zmienne Dim Czujniki_licznik As Byte , Czujniki(6) As Integer , Flagalinii As Byte Dim Waga_czujnika(7) As Integer , Suma_wag As Integer , Ile_wykrylo As Byte Dim Aktualna_pozycja As Single , Blad As Single , Czulosc As Integer , Docelowa_predkosc As Byte , Zmiana As Integer Czulosc = 255 - 100 Czulosc = Czulosc / 14 Docelowa_predkosc = 100 Waga_czujnika(1) = 14 Waga_czujnika(2) = 13 Waga_czujnika(3) = 12 Waga_czujnika(4) = -12 Waga_czujnika(5) = -13 Waga_czujnika(6) = -14 'stany poczatkowe na mostku i diodzie Set Silnik_lewy_a Reset Silnik_lewy_b Set Silnik_prawy_a Reset Silnik_prawy_b Set Dioda 'granica reagowania na linie Const Granica = 750 'docelowa pozycja Const Docelowa_pozycja = 0 Do Gosub Czytaj Gosub Licz_pozycje Gosub Licz_pid Pwm1a = Docelowa_predkosc + Zmiana Pwm1b = Docelowa_predkosc - Zmiana Loop End Czytaj: For Czujniki_licznik = 0 To 5 Czujniki(czujniki_licznik + 1) = Getadc(czujniki_licznik) If Czujniki(czujniki_licznik + 1) > Granica Then Set Flagalinii.czujniki_licznik Else Reset Flagalinii.czujniki_licznik Next Return Licz_pozycje: Suma_wag = 0 Ile_wykrylo = 0 For Czujniki_licznik = 0 To 5 If Flagalinii.czujniki_licznik = 1 Then Suma_wag = Suma_wag + Waga_czujnika(czujniki_licznik + 1) Ile_wykrylo = Ile_wykrylo + 1 End If Next Aktualna_pozycja = Suma_wag / Ile_wykrylo Return Licz_pid: Blad = Docelowa_pozycja + Aktualna_pozycja Zmiana = Czulosc * Blad Return
  4. Prędkość nie będzie grała tak dużej roli. Nie będę go brał na żadne zawody. Może po ukończonym lf przełożę silniczki do robota sumo
  5. Zależy mi na dużym momencie obrotowym, więc wolałem dopłacić te "parę" złotych :->
  6. Faktycznie lepiej będzie zrobić złącze nawet 8 pinowe sześć pinów na czujniki, jeden na +5V i jeden na GND. Schemat poprawiłem. Silniczki których będę używał to mikrosilniki pololu. Właśnie kupiłem je na http://botland.com.pl/silniki/116-silnik-pololu-hp-298-1.html (nie są takie tanie). Najważniejsze że zakup mam już za sobą
  7. Witam, Mam prośbę o sprawdzenie schematu. Nie trudno się domyślić że jest to schemat line followera z wykorzystaniem sześciu kanałów na wyjścia transoptorów (czujników) odbiciowych. Pozostał jeszcze do zrobienia moduł z czujnikami jednak z tym najmniej problemów. Co do schematu wydaje mi się, że kondensatory na L298 przy VCC są zbędne gdyż napięcie jest już filtrowane przy stabilizatorze, ale zostawiłem je i wolałem zapytać dla pewności. Proszę o wyjaśnienie czego brakuje, co jest zbędne, ewentualne uwagi. W załączniku dołączam plik schematu. Pozdrawiam untitled.sch
  8. bluehais

    Czy to ma prawo działać ?

    To zrób tak:
  9. bluehais

    [Bascom] Sterowanie rc5

    Witam, mam pytanie odnośnie tego programu (nie mojego autorstwa). Wszystko jasne tylko nie rozumiem tego fragmentu: Command = Command And &B01111111 0111 1111 to 1+2+4+8+16+32+64=127 dec . Skąd wiadomo że po pomnożeniu tej wartości przez wartość zmiennej Command pobranej z pilota da wynik np. 2 ,8,6,4 itd. Są do tego jakieś tablice? Program: $regfile = "m8def.DAT" $crystal = 8000000 Config Rc5 = Pinb.0 'ustawienie pinb.0 jako odbiór sygnału IR Dim Adres As Byte , Command As Byte 'zmienne Dim Speed As Integer Enable Interrupts 'włączenie przerwań Config Portc = Output 'port c jako wyjścia Portc = &B00000000 'wszędzie stan spoczynkowy-0 '-------konfiguracja timera do generowania sygnału PWM warunkującego prędkość pojazdu Config Timer1 = Pwm , Pwm = 8 , Compare A Pwm = Clear Down , Compare B Pwm = Clear Down , Prescale = 1 Speed = 255 'prędkośc na maksa Do 'poczatek programu Getrc5(adres , Command) 'pobierz adres i komende z pilota Command = Command And &B01111111 Waitms 50 'warunki i odwołania do podprogramów If Command = 2 Then Gosub Przod End If If Command = 8 Then Gosub Tyl End If If Command = 4 Then Gosub Lewo End If If Command = 6 Then Gosub Prawo End If 'regulacja prędkości. Dostosuj wartosci komend do swojego pilota! If Command = 32 Then Incr Speed If Speed = 251 Then Speed = 250 End If End If If Command = 33 Then Decr Speed If Speed = 1 Then Speed = 2 End If End If 'koniec regulacji prędkości If Command = 127 Then Pwm1a = 0 'komenda 127 podawana jest kiedy If Command = 127 Then Pwm1b = 0 'procesor nie odbiera sygnału z nadajnika 'przy tej komendzie stój! Loop 'koniec pętli End '--------------------------------------------------- 'podprogramy: Przod: Do Waitms 50 ' gasienica prawa Pwm1a = Speed Set Portc.0 Reset Portc.1 ' gasienica lewa Pwm1b = Speed Set Portc.2 Reset Portc.3 If Command = 2 Then Return Loop End Tyl: Do Waitms 50 ' gasienica prawa Pwm1a = Speed Set Portc.1 Reset Portc.0 ' gasienica lewa Pwm1b = Speed Set Portc.3 Reset Portc.2 If Command = 8 Then Return Loop End Lewo: Do Waitms 50 ' gasienica prawa Pwm1a = Speed Set Portc.0 Reset Portc.1 ' gasienica lewa Pwm1b = Speed Set Portc.3 Reset Portc.2 If Command = 4 Then Return Loop End Prawo: Waitms 50 ' gasienica prawa Pwm1a = Speed Set Portc.1 Reset Portc.0 ' gasienica lewa Pwm1b = Speed Set Portc.2 Reset Portc.3 If Command = 6 Then Return Return
  10. Witam, Mam taki problem. Chcę by w programie po zadziałaniu jednego z czujników jeden z silników obracał się przez 1 sekundę (tylne obroty) i analogicznie jeśli drugi zadziała również ten sam silnik (tylne obroty) lub oba zadziałają (czyli wartość spadnie poniżej granicy) również ma się obracać przez sekundę ten sam silnik (tylne obroty) a jeżeli będzie inaczej na obu silnikach będą włączone przednie obroty. Napisałem taki program (niżej), ale silniki dziwnie się zachowują. Gdy nie ma białej kartki blisko czujników (czujnika) układ samoczynnie włącza tylne obroty jednego z silników na czas 1s. Pierwsze moje skojarzenie to takie że pierwszy odczyt z czujnika może mieć dość wysoką wartość która przekracza granicę i tym jest to spowodowane. Tyle już kombinowałem i nic. Czy da się jakoś przywrócić to do ładu? Dodam że wcześniej bez dodania "Wait 1" wszystko działało dobrze, ale chciałem tak zrobić by tuż po krótkim impulsie mniejszym od Granicy uC włączał silnik na 1 sekundę (niezależnie jaka wartość będzie na ADC w ciągu tej 1 sekundy) a nie całyczas "patrzył" i przyrównywał wartość na ADC do Granicy. Mam nadzieję że wiecie o co mi chodzi Oto program: $regfile = "m8def.dat" $crystal = 1000000 Config Adc = Single , Prescaler = Auto Config Portd = Output Config Portb = Output Silnik_lewy_a Alias Portd.3 Silnik_lewy_b Alias Portd.2 Silnik_prawy_b Alias Portd.0 Silnik_prawy_a Alias Portd.1 Const Granica = 1020 Dim Czujnik_prawy As Single Dim Czujnik_lewy As Single Dim W As Word Reset Silnik_lewy_a Reset Silnik_lewy_b Reset Silnik_prawy_a Reset Silnik_prawy_b Do Gosub Wczytaj_stany If Czujnik_lewy < Granica And Czujnik_prawy < Granica Then Silnik_lewy_a = 1 'do tyłu Silnik_lewy_b = 0 Silnik_prawy_a = 1 Silnik_prawy_b = 0 Wait 1 Elseif Czujnik_lewy < Granica And Czujnik_prawy > Granica Then Silnik_lewy_a = 1 Silnik_lewy_b = 0 Silnik_prawy_a = 0 Silnik_prawy_b = 0 Wait 1 Elseif Czujnik_prawy < Granica And Czujnik_lewy > Granica Then Silnik_lewy_a = 0 Silnik_lewy_b = 0 Silnik_prawy_a = 1 Silnik_prawy_b = 0 Wait 1 Else Silnik_lewy_a = 0 ' do przodu Silnik_lewy_b = 1 Silnik_prawy_a = 0 Silnik_prawy_b = 1 End If Loop End Wczytaj_stany: Start Adc W = Getadc(5) W = Getadc(5) Stop Adc Czujnik_lewy = W Start Adc W = Getadc(3) W = Getadc(3) Stop Adc Czujnik_prawy = W Return __________ Komentarz dodany przez: Treker
  11. bluehais

    Cny70 - coś nie tak

    OldSkull Działa problem rozwiązało zwykłe dociśnięcie czujnika do płytki stykowej (ma już swoje lata) :-> Pozdrawiam
  12. bluehais

    Cny70 - coś nie tak

    Witam Problemy z cny70 były już poruszane i właśnie je czytałem, jednak wydaje mi się, że mój problem jest inny. Właśnie testowałem transoptory przed wlutowaniem. Bateria 9V do stablilizatora i od 7805 poprowadziłem przez rezystor 240 Ohm plus do anody diody, minus natomiast do katody (dioda nie świeci) sprawdzałem też czy po przyłożeniu białej kartki fototranzystor zacznie przewodzić (w mierniku charakterystyczny "pisk"). Jednak nic z tego, nie przewodzi. Spróbowałem dać czujnik pod światło i fototranzystorek przewodził, więc z nim wszystko ok. Co może być z diodą? Może coś źle z zasilaniem, podłączeniem, a może rezystancja za duża? __________ Komentarz dodany przez: Treker
  13. Sorki że jeszcze raz pytam, ale tak z ciekawości czy silniki, uC i czujniki zasilasz z tego samego zasilania?
  14. Dzisiaj jeszcze raz wyciągnąłem każdy wałek, zębatkę i nasmarowałem ale ten sam efekt. Przy początkowych testach, serwa zasilałem baterią od se k510i ( niecałe 4V ) :->. Luko pewnie masz rację. Nie ukrywam, że było to chyba jedno z najtańszych mikroserw na allegro (jak nie najtańsze), więc nie mogę mieć pretensji do działania. Trochę naciąłem się na cenę, ale następnym razem wiem jakie serwa omijać
  15. Porównywałem z tym pierwszym wszystkie leżą na swoim miejscu. Hmm, może to jakaś wada fabryczna źle dobrane średnice zębatek
×