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 C to Oshonsoft

Discussion in 'Oshonsoft' started by camerart, May 5, 2017.

  1. camerart

    camerart Active Member

    Joined:
    Jun 12, 2008
    Messages:
    1,368
    Likes:
    11
    Location:
    Dorset UK.
    Hi,
    I'm trying to translate some code from C to Oshonsoft, and I'm a bit stuck!

    Here is the code below for a PIC controlled radio module SX1278. If it's understandable, how would this be written in Oshonsoft please?
    Camerart.

    Variables;
    SIZE
    X
    LENGTH
    DATA

    FROM SX1278 DATA SHEET
    Reading the SX1278 RxNbBytes Register gives the number of bytes received so far = SIZE
    Reading the FIFO is receiving the DATA

    Writing the PayLoadLength sets number in the Register
    Write FIFO DATA Transmit FIFO DATA until x = LENGTH

    CODE:

    size = ReadSPI(GetRxNbBytes())
    while (x < size)
    SPIRead(GetFifo())
    x = x+1

    WriteSPI(SetPayloadLength(length))
    while (x < length) {
    WriteSPI(SetFifo(data[ x ]))
    x = x+1
     
    Last edited: May 6, 2017
  2. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,251
    Likes:
    911
    Location:
    Rochdale UK
    That isn't C... That is basic... Or someone is rubbish at C... C must have ';' at the end of each statement..

    Its more like a cross between the two....

    In Oshonsoft ( after setting the SPI definitions )

    SPICSON
    SPISEND rxnbytesADDR
    SPIRECIEVE rxnbytes
    SPISEND fifoADDR
    for i = 0 to rxnbytes-1
    SPIRECIEVE data(i)
    next i
    SPICSOFF

    Something like this UNTESTED!!!!!
     
  3. camerart

    camerart Active Member

    Joined:
    Jun 12, 2008
    Messages:
    1,368
    Likes:
    11
    Location:
    Dorset UK.
    Hi I,
    You're correct, that it's rubbish C. I wrote it from C notes, and I can't speak C:), but you appear to have understood it.

    I before E except after C ;)

    Thank you, C.
     
  4. dave

    Dave New Member

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


     
  5. Pommie

    Pommie Well-Known Member Most Helpful Member

    Joined:
    Mar 18, 2005
    Messages:
    10,083
    Likes:
    326
    Location:
    Brisbane Australia

    Shouldn't there be two for loops?

    Mike.
     
  6. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,251
    Likes:
    911
    Location:
    Rochdale UK
    Maybe Mike..... I haven't time right now to check it!!!
     
  7. camerart

    camerart Active Member

    Joined:
    Jun 12, 2008
    Messages:
    1,368
    Likes:
    11
    Location:
    Dorset UK.
    Hi M and I,

    True there will be two of similar sections of CODE to I's example, but inside one loop. I will be able too work it out though.
    C.
     
  8. camerart

    camerart Active Member

    Joined:
    Jun 12, 2008
    Messages:
    1,368
    Likes:
    11
    Location:
    Dorset UK.
    Hi,
    I spoke too soon! It is just too difficult, because there are too many differences between the code I'm transferring and Ian's code, and it would be better if it was in two sections, as there is a fair bit that goes on between them.
    Also it would be better if it had the same variables please.
    C.
     

Share This Page