Pages

Wednesday, May 22, 2013

fongtoy module fttest notes

Now I have added yet another fongtoy module called fttest which consists test functions.

The main program now tests EEPROM at addresses 0 and 1.  

fttest.TestDemuxEeprom(mcp23s17SubAddress = 0, eepromDemuxAddress = 0, testStartAddress = 0x0123, testWriteDataByte = 0x5a)

fttest.TestDemuxEeprom(mcp23s17SubAddress = 0, eepromDemuxAddress = 1, testStartAddress = 0x0123, testWriteDataByte = 0x3b)


The test function prints results indicating good and bad EEPROMS.


*** EEPROM demux address =  0  ***

Write start address =  0x123
Write data byte =  0x5a

Read back start address =  0x123
Read back data byte  =  0x5a

 ### EEPROM good. ###


*** EEPROM demux address =  1  ***

Write start address =  0x123
Write data byte =  0x3b

Read back start address =  0x123
Read back data byte  =  0xff

 ### EEPROM bad!!! ###


# ftmain v1.21 tlfong01 2013may22

ProgramTitle = "FongToy v1.21 tlfong01 2013may22 "

import sys 
import time 
import smbus 
import pdb 
import spidev 
import wiringpi
import wiringpi2
import RPIO as GPIO  
from RPIO import PWM 
from enum import Enum 
from subprocess import call

import ftio
import ftprint
import ftspi
import ftiox
import fteeprom
import ftguzuntypi
import ftdemux
import fttest

# *** Main program ***

# *** Start program message ***

ftprint.StartProgram(ProgramTitle)

# *** Old test functions ***

# ftspi.TestSpiLoopBack(spiChannelNumber = 0, spiChipEnableNumber = 1, testDataByte = 0x55, testCount = 1000, testTime = 0.001)
# ftiox.TestMcp23s17BlinkLed(spiChannelNumber = 0, spiChipEnableNumber = 0, spiChipSubAddress = 0)
# fteeprom.TestWriteReadEepormDataByte(spiChannelNumber = 0, spiChipEnableNumber = 1, startAddress = 0x0410, testDataByte = 0x55)
# ftguzuntypi.TestGuzuntyPi4digit7segmentLedModule(spiChannelNumber = 0, spiChipEnableNumber = 1)
# ftdemux.TestSelectSpiSlaveDevice(spiChannelNumber = 0, spiChipEnableNumber = 0, spiIoxSubAddress = 0, spiSlaveDeviceNumber = 2)

# *** New test functions ***

fttest.TestDemuxEeprom(mcp23s17SubAddress = 0, eepromDemuxAddress = 0, testStartAddress = 0x0123, testWriteDataByte = 0x5a)

fttest.TestDemuxEeprom(mcp23s17SubAddress = 0, eepromDemuxAddress = 1, testStartAddress = 0x0123, testWriteDataByte = 0x3b)

# *** Stop program message ***

ftprint.StopProgram()

#.END


# fttest.py v1.2 tlfong01 2013may22

import time
import spidev

import ftprint
import ftiox
import ftspi
import fteeprom
import ftdemux

# *****************************************************************************
# Function - TestDemuxEeprom()
# Description - Read after Write EEPROM
# Sample call - 
#   fttest.TestDemuxEeprom(mcp23s17SubAddress = 0, eepromDemuxAddress = 0, testStartAddress = 0x0410, testWriteDataByte = 0x5a)
# Sample output - 
#   ...
# *****************************************************************************

def TestDemuxEeprom(mcp23s17SubAddress, eepromDemuxAddress, testStartAddress, testWriteDataByte):

    # *** Setup SPI channels MCP23s17Demux and EEPROM ***

    spiChannelDemux = spidev.SpiDev() 
    spiChannelDemux.open(0, 0)

    spiChannelEeprom = spidev.SpiDev() 
    spiChannelEeprom.open(0, 1)

    # *** Select EEPROM #1 ***

    ftdemux.SelectSpiSlaveDevice(spiChannelDemux, mcp23s17SubAddress, eepromDemuxAddress)
    print "\n\n*** EEPROM demux address = ", eepromDemuxAddress, " ***"

    # *** Test EEPROM ***

    fteeprom.WriteEepromDataByte(spiChannelEeprom, testStartAddress, testWriteDataByte)
    print "\nWrite start address = ", hex(testStartAddress)
    print "Write data byte = ", hex(testWriteDataByte)

    readBackDataByte = fteeprom.ReadEepromDataByte(spiChannelEeprom, testStartAddress)
    print "\nRead back start address = ", hex(testStartAddress)
    print "Read back data byte  = ", hex(readBackDataByte)

    if (testWriteDataByte == readBackDataByte):
      print "\n ### EEPROM good. ###"
    else:
      print "\n ### EEPROM bad!!! ###"

    spiChannelDemux.close() 
    spiChannelEeprom.close() 

# .END

No comments:

Post a Comment