1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

Converting Arduino to Oshonsoft.

Discussion in 'Oshonsoft' started by camerart, Oct 16, 2016.

  1. camerart

    camerart Active Member

    Joined:
    Jun 12, 2008
    Messages:
    1,190
    Likes:
    11
    Location:
    Dorset UK.
    Hi,

    I assume that Arduino is written in 'C' is this correct?

    If I see a line: shiftin sdo, sck, 0,(nindata) What would the equivalent be in Oshonsoft Basic? Also for OUT please?

    Camerart.
     
  2. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    8,875
    Likes:
    862
    Location:
    Rochdale UK
    Arduino's primary language is C++.. This is basically a software serial read.. Oshonsoft hasn't this function but you could use the software SPI to do this...
     
  3. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,011
    Likes:
    636
    Location:
    Ex Yorks' Hants UK
    hi C,
    This modified example is from the OSH manual
    The BOLD character block is a read input.
    E
    Example 1:
    AllDigital
    Define SPI_CS_REG = PORTC
    Define SPI_CS_BIT = 0
    Define SPI_SCK_REG = PORTC
    Define SPI_SCK_BIT = 3
    Define SPI_SDI_REG = PORTC
    Define SPI_SDI_BIT = 4
    Define SPI_SDO_REG = PORTC
    Define SPI_SDO_BIT = 5
    SPIPrepare

    Dim addr As Byte
    Dim data As Byte

    For addr = 0 To 10
    data = 200 - addr
    SPICSOn
    SPISend 0x06
    SPICSOff
    SPICSOn
    SPISend 0x02
    SPISend addr
    SPISend data
    SPICSOff
    WaitMs 500
    Next addr

    For addr = 0 To 10
    SPICSOn
    SPISend 0x03
    SPISend addr
    SPIReceive data
    SPICSOff
    WaitMs 500
    Next addr
     
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,011
    Likes:
    636
    Location:
    Ex Yorks' Hants UK

    hi C,

    This a clip from a NRF radio program I have written.

    On Interrupt
    Save System
    'interrupt on any Pipe RXD

    INTCON.INTF = 0
    rxd_led = 1

    'RX receive
    receive:
    SPICSOn
    SPISend rd_rx_pload
    WaitUs 10

    For x = 0 To dta_len
    SPIReceive rx_dta(x)
    WaitUs 10
    Next x


    SPICSOff
     
  6. camerart

    camerart Active Member

    Joined:
    Jun 12, 2008
    Messages:
    1,190
    Likes:
    11
    Location:
    Dorset UK.
    Hi,
    Thanks, both.

    I've placed the above code into my program and there are pins ON/OFFing. Thanks.

    I'm trying to program an 18F4520 to fill a RFM radio module registers, as set in the Data sheet, then a LOOP to use the RFM by sending/receiving DATA.

    The Register data looks like this:
    'Clk output is 2 MHz
    naddress = $0a
    noutdata = $05
    Gosub spi_out
    'GPIO0 is RX data output
    naddress = $0b
    noutdata = $f4

    And the sending/receiving DATA could be an NMEA sentence for example.

    C.
     
  7. ericgibbs

    ericgibbs Well-Known Member Most Helpful Member

    Joined:
    Jan 4, 2007
    Messages:
    21,011
    Likes:
    636
    Location:
    Ex Yorks' Hants UK
    hi C
    This is an example of how I write to radio by SPI
    E

    SPICSOn
    SPISend rx_pw_p1 '0x32 this is the address of the reg you want to write too.
    WaitUs 10
    SPISend dta_len ' this is the data that will be written to that address
    SPICSOff
    WaitUs 20

    So yours:
    The Register data looks like this:
    'Clk output is 2 MHz
    naddress = $0a
    noutdata = $05
    Gosub spi_out
    'GPIO0 is RX data output
    naddress = $0b
    noutdata = $f4

    becomes:
    SPICSOn
    SPISend $0a this is the address of the reg you want to write too.
    WaitUs 10
    SPISend $05' this is the data that will be written to that address
    SPICSOff
    WaitUs 20

    SPICSOn
    SPISend $0b this is the address of the reg you want to write too.
    WaitUs 10
    SPISend $f4' this is the data that will be written to that address
    SPICSOff
    WaitUs 20
     
  8. camerart

    camerart Active Member

    Joined:
    Jun 12, 2008
    Messages:
    1,190
    Likes:
    11
    Location:
    Dorset UK.
  9. camerart

    camerart Active Member

    Joined:
    Jun 12, 2008
    Messages:
    1,190
    Likes:
    11
    Location:
    Dorset UK.
    Hi,
    Here's a snippet of code that's been sent to me: Can it be made to work in Oshonsoft, or is my attached code as good? Mine compiles in SIM ok. It's for loading registers for radio module set-up.
    C.

    Write(RegOpMode, 0x00); //Putting RADIO to sleep
    Write(RegOpMode, 0x80); //Switch to LoRa mode
    Write(RegOpMode, 0x81); //Setting RADIO to standby
    while (digitalRead(DIO5) == LOW) //Wait for mode ready
    {
    }
    --Now it is time to make your register settings here--
    --And now we leave standby.
    Code: [Select]
    Write(RegOpMode, 0x85); //Set RADIO to continuous receive
    while (digitalRead(DIO5) == LOW) //Wait for mode ready
    {
    }

    EDIT:D105 refers to a PIN on the radio module.
     

    Attached Files:

    Last edited: Oct 23, 2016

Share This Page