Any reason this simple code works on Pic24 and not pic18

Information and discussion regarding the main Firewing development board

Any reason this simple code works on Pic24 and not pic18

Postby Timbo » Sun Jul 15, 2018 9:00 pm


This is some old code below that I'm testing now runs fine on the Pic24 Firewing board but not on the 18 series.

The shield is a simple power and 2 pullups for the SLC and SDA lines on _D2 and _D3

On the Pic24 series I get back sensible data on the Pic18 I get back 0x7FFF which is all bits set

Code: Select all
// tested On Firewing For PIC24 board R2, compiler Firewing 16
// configure Then import module...
#option I2C_SCL = _D2   ' 5v tolerent on PIC24, PIC32
#option I2C_SDA = _D3   ' 5v tolerent on PIC24, PIC32
#option I2C_DELAY_US = 3
imports I2c             

// Device constants...
private const START_CYC_RAM As Byte = &H02
private const CFG_SIF_TO_I2C As Byte = &H52
private const START_NOM As Byte = &H71
private const I2C_DEVICE_ADDRESS As Byte = &H78 << 1

// program entry point...
Sub Main()

    Dim Tally As Ulong = 0
    Dim Index As Byte = 0
    Dim TallyAverage As Ushort
    Dim Barg As Ushort   
   // Loop forever...
   While true           
      // read data - High Byte, Low Byte
      // The pressure is transferred As 15 Bit value (Bit 0 – 14). From the 15
      // Bit measured values, approx. 12 Bit are used As resolution, the three
      // least significant bits can be ignored.
      Dim Result As ushort
      I2C.WriteByte(I2C_DEVICE_ADDRESS + 1)                                     ' Address the device and tell it you want to do a read by setting the LSB to 1
      Result.Byte1 = I2C.ReadByte()                                             ' Read in the MSB
      I2C.Acknowledge(IsAcknowledge)                                            ' Send an ACK
      Result.Byte0 = I2C.ReadByte()                                             ' Read in the LSB
      I2C.Stop()                                                                ' Send the stop
      Result = Result >> 1                                                      ' Were interested in only 14 bits
    Console.Write("value = ", CStr(Result),13,10)

   End While
 End Sub
Posts: 93
Joined: Fri May 03, 2013 7:51 pm

Return to Main Board

Who is online

Users browsing this forum: No registered users and 1 guest