Welcome to our new forum
All users of the legacy CODESYS Forums, please create a new account at account.codesys.com. But make sure to use the same E-Mail address as in the old Forum. Then your posts will be matched. Close

mcp3008 issue on raspi3 model b+

thierrytri
2018-04-29
2018-06-06
  • thierrytri - 2018-04-29

    i am trying a pi model 3 b+ with the same program than the model 3, with a mcp3008.
    on the model b+, the spi is enable, works with a python program, but not with Codesys.
    The wiring is the same, the parameters too (/dev/spidev0.0), it work on the model 3, but not the model 3 b+.
    Someone have an idea ?
    thanks

     
  • eschwellinger

    eschwellinger - 2018-04-30

    Hi,
    guess this might solve your Problem(reduce SPI speed):
    l viewtopic.php?f=21&t=8658 l
    BR
    Edwin

     
  • thierrytri - 2018-05-01

    HI
    Many thanks Edwin, it works for me, great!
    Thierry

     
  • thierrytri - 2018-05-12

    Hi
    i have a last problem witrh mcp3008:
    i wired 2 mcp 3008 the first with chip select on pin 26, the second with chip select on pin 24.
    I set 2 spi master , the first on /dev/spidev0.0, the second on /dev/spidev0.1.
    It works, but when the two are wired, it seems adding the 2 values on the same input mcp3008.auiValue[0], with the mcp3008_1.auiValue[0].
    Have i proceed in the wrong way ?
    Thanks
    Thierry

    IMG: Screenshot2.png

    IMG: Screenshot1.png

     
  • JLo - 2018-06-06

    Hi,

    I used two max6675 sensors to read two temps as you described that worked well. I noticed that in the driver in block 'AfterReadInputs' the transfer is immediately restarted after finishing, then I got a reading only at start of the program.
    I solved this by adding a delay of a few cycles before restarting the transmission again which did the trick.
    This allows you to read max two sensors.
    Also noticed that you can manipulate the chip enable by disconnecting the wire, so in theory you can use gpio's to control the demultiplexing of multiple sensors.

    See a copy of the driver routine;

    SUPER^.AfterReadInputs();

    IF _iState = 10 THEN
    
        aby[0] := 0;
        aby[1] := 0;
    
        IF  transfer(pabyTxBuffer:=ADR(aby) , pabyRxBuffer:=ADR(aby) , udiLen:=2 , uiDelayus:=5) THEN
            _iState := 20; // jump out of step to stop transmission
        END_IF
    
        ui := aby[1];
        ui := ui + (BYTE_TO_UINT(aby[0])) * 256;
        auiValue := ui/4;
    
    END_IF;
    
    // delay restart of trasnmission
    IF _iState >10 THEN
    
        _iState := _iState - 1;
    
    END_IF;
    
     

Log in to post a comment.