ts-7000
[Top] [All Lists]

[ts-7000] Help reading DIO lines 7260

To:
Subject: [ts-7000] Help reading DIO lines 7260
From: "pgb_psu" <>
Date: Wed, 09 May 2007 16:18:05 -0000
I'm trying to learn how to read the DIO pins on the DIO1 header on my TS-7260.  
My first 
step is simply reading pin 1 (DIO_0) and placing that value on pin 9 (DIO_4).  
I've got a 
function generator putting out a square wave as my input signal.  That signal 
is connected 
to gnd (pin 2) and dio_0 (pin 1) on the DIO1 header.  I've got one scope probe 
watching 
the function generator (pin 1 and pin 2) and the second probe connected to pins 
2 and 9 
(gnd and DIO_4) of DIO1.  When I run the following program, DIO_4 (pin 9) does 
not 
shadow DIO_0 (pin 1).  

I've tried a wide range frequencies thinking that maybe the frequency of the 
square wave 
I'm using is too fast.  However, even at 1Hz this program does not work so I'm 
convinced 
my problem is in the C code.  I'm new to c so I simply took the read_temp.c 
program 
provided by TS and hacked it to produce the code below and the first bit of 
output.  

/********************************
 * program to read the read data on DIO1 header pin 1 and place that value on 
pin 9
 * hacked from tempSensor.c provided by TS.
 * PGB 8 May 2007
 * Peter Burkett <>
 *******************************/
 /********************************
 *Simple program to demonstrate
 *reading a temperature using 
 *tmp124 on a TS-7200
 *
 *EWD Oct. 22 2004
 *Eddie Dawyiduk <>
 *******************************/

#include "peekpoke.h"
#include<unistd.h>
#include<sys/types.h>
#include<sys/mman.h>
#include<stdio.h>
#include<fcntl.h>
#include<assert.h>
#include<time.h>


/*Register addresses */
#define DIO_PAGE                0x80840000UL

/*Offsets*/
#define PORTB_DR                0x04
#define PORTB_DDR               0x14
#define PORTF_DR                0x30
#define PORTF_DDR               0x34


int main(int argc, char **argv)
{

        unsigned int bits_0123;
        unsigned int bits_4567;
        unsigned int tmp;
        volatile unsigned char *dio_page;
        int fd = open("/dev/mem", O_RDWR);
        assert(fd != -1);

        /* Lets intialize our pointers */
        dio_page = mmap(0, getpagesize(), PROT_READ|PROT_WRITE, MAP_SHARED, fd, 
DIO_PAGE);
        assert(dio_page != MAP_FAILED);

        // Set our DIO pins 0-3 as inputs and 4-7 as outputs 
        // bits 0-3 in 0x8084_0014 should be cleared (0) for input
        // bits 4-7 in 0x8084_0014 should be set (1) for output
        tmp = PEEK8( (unsigned long)(dio_page + PORTB_DDR));
        printf("Value of PORTB_DDR when program starts: 0x%x \n", tmp);

        POKE8( (unsigned long)(dio_page + PORTB_DDR), 0xF0 );
        tmp = PEEK8( (unsigned long)(dio_page + PORTB_DDR));
        printf("Value of PORTB_DDR after setting it to 0xf0: 0x%x \n", tmp);
        tmp = PEEK8( (unsigned long)(dio_page + PORTB_DR));
        printf("Value of PORTB_DR befor loop: 0x%x \n", tmp);

        // setup while loop to read DIO_0-DIO_3 and shadow them on DIO_4-DIO_7
        while (1)  {
                bits_0123 = PEEK8((unsigned long)(dio_page + PORTB_DR) );
                printf("Value of PORTB_DR in loop: 0x%x \n", bits_0123);

                bits_0123 <<= 4;   // shift bits 0-3 into positions 4-7
                bits_4567 = bits_0123 & 0x0F0;  //AND bits to clear bits above 
bit 7
                printf("Value written to PORTB_DR after shift: 0x%x \n", 
bits_4567);
                
                // write the word out
                POKE8( (unsigned long)(dio_page + PORTB_DR), bits_4567);
                tmp = PEEK8((unsigned long)(dio_page + PORTB_DR));
                printf("Value of PORTB_DR after write: 0x%x \n\n", tmp);

                usleep(100);
        
        }

        return 0;

}

Value of PORTB_DDR when program starts: 0xf0 
Value of PORTB_DDR after setting it to 0xf0: 0xf0 
Value of PORTB_DR befor loop: 0xbb 
Value of PORTB_DR in loop: 0xbb 
Value written to PORTB_DR after shift: 0xb0 
Value of PORTB_DR after write: 0xbb 

Value of PORTB_DR in loop: 0xbb 
Value written to PORTB_DR after shift: 0xb0 
Value of PORTB_DR after write: 0xbb 




 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/ts-7000/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/ts-7000/join
    (Yahoo! ID required)

<*> To change settings via email:
     
    

<*> To unsubscribe from this group, send an email to:
    

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 

<Prev in Thread] Current Thread [Next in Thread>
Admin

Disclaimer: Neither Andrew Taylor nor the University of NSW School of Computer and Engineering take any responsibility for the contents of this archive. It is purely a compilation of material sent by many people to the birding-aus mailing list. It has not been checked for accuracy nor its content verified in any way. If you wish to get material removed from the archive or have other queries about the archive e-mail Andrew Taylor at this address: andrewt@cse.unsw.EDU.AU