Shop OBEX P1 Docs P2 Docs Learn Events
SX48 pins — Parallax Forums

SX48 pins

GOTigerGOTiger Posts: 4
edited 2007-09-20 21:53 in General Discussion
Hi, I met a problem once I am using the DLP-245SY-G which uses the SX48 controller. Actually I am using the application TOKEN 245SY.
Every time, when I read or write the Port B, C, E, the Port D databus will go HIGH. What's the link between Port D with other Ports?

I don't know is the problem relating to the SX48 chip or not?

Thanks.

Comments

  • ElectronegativityElectronegativity Posts: 311
    edited 2007-09-20 20:22
    Hi GoTiger.

    I looked on Mouser's website at the board and it mentions shipping with sample code installed that enables the SX48 to communicate with the USB driver.
    This could be causing the issue.
    Do you have, or can you get a copy of the code that comes installed on the device?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    I wonder if this wire is hot...
  • GOTigerGOTiger Posts: 4
    edited 2007-09-20 20:43
    Here is the code. Could you please take a look? Thanks.

    void main()
    {
    //1111 1100 port A idle state: 7654 3210 1=input 0=output
    ddra = 0xfc;
    asm(mov w,ddra); asm(mov !porta,w );

    //1000 1111 port B idle state: 7654 3210 1=input 0=output
    ddrb = 0x8f;
    asm(mov w,ddrb); asm(mov !portb,w );

    //0011 0000 port C idle state: 7654 3210 1=input 0=output
    ddrc = 0xff;
    asm(mov w,ddrc); asm(mov !portc,w);

    SETPORTDIN;//make port d all input

    //1111 1111 port E idle state: 7654 3210 1=input 0=output
    ddre = 0xff;
    asm(mov w,ddre); asm(mov !porte,w );

    //init USB and LED
    asm(setb porta.0);//take RD high
    asm(setb porta.1);//take WR high
    asm(setb portb.4);//take SND high
    asm(clrb portb.5);//turn led on

    asm(clr !wdt);//pet the dog
    delay_msec(200);//power up delay


    asm(mov w,porta); asm(mov tt,w); tt &= 0x08;//read RXF
    if(tt==0)//purge USB FIFO
    {
    asm(clrb porta.0);//take RD low
    asm(setb porta.0);//take RD high
    }


    //FLASH LED
    for(tt=0; tt<10; tt++)
    {
    asm(clr !wdt);//pet the dog
    asm(setb portb.5);
    delay_msec(40);
    asm(clrb portb.5);
    delay_msec(40);
    }

    led_count=0;
    led_count1=0;
    while(1)
    {
    asm(clr !wdt);//pet the dog

    toggle_led();

    //byte received in FIFO buffer...
    asm(mov w,porta); asm(mov tt,w); tt &= 0x08; //read RXF
    if(tt==0)
    {
    receive_packet();

    mptr = &buffer;
    mptr++;
    cmd = *mptr;
    *mptr=0;

    switch(cmd)
    {
    case 0xA7: //if Return Board ID command...
    send('2');
    send('4');
    send('5');
    send('S');
    send('Y');
    strobe_SND();//send now
    cmd = 0;
    break;
    case 0xAF: //if Loopback test
    send(buffer);
    strobe_SND();//send now
    cmd = 0;
    break;
    case 0xAA: //if EEPROM Read
    tmp = ee_read(0xA1, buffer);
    send(tmp);
    strobe_SND();//send now
    cmd = 0;
    break;
    case 0xAB: //if EEPROM Write
    ee_write(0xA0, buffer, buffer);
    cmd = 0;
    break;

    case 0xAC: //if temperature start convert command
    d_pin = buffer;
    D_Reset();
    if(D_Error < 99)
    {
    send(D_Error);//return error
    cmd=0;
    break;
    }
    else
    send(0x63);//return no error (99)
    Write_byte(0xcc);//skip rom command
    Write_byte(0x44);//Convert temperatures
    cmd = 0;
    break;

    case 0xAD: //if temperature read command -
    d_pin = buffer;

    D_Reset();
    Write_byte(0xcc);//skip rom command
    Write_byte(0xbe);//read scratch pad
    delay_usec(5);
    for(tt=0; tt<9; tt++)
    {
    tmp = Read_byte();
    send(tmp);
    }
    strobe_SND();//send now
    cmd = 0;
    break;

    case 0x57: //if Port B read
    //11001111 keep some output
    ddrb = 0xcf;//make port b partial input
    asm(mov w,ddrb); asm(mov !portb,w );
    send( portb );
    cmd = 0;
    strobe_SND();//send now
    break;
    case 0x58: //if Port B write
    //11010000 leave EE data as input
    ddrb = 0xD0;//make port b partial output
    asm(mov w,ddrb); asm(mov !portb,w );
    portb = buffer;
    cmd = 0;
    break;

    case 0x59: //if Port C read
    ddrc = 0xff;//make port c all input
    asm(mov w,ddrc); asm(mov !portc,w );
    send( portc );
    cmd = 0;
    strobe_SND();//send now
    break;
    case 0x5A: //if Port C write
    ddrc = 0x0;//make port c all output
    asm(mov w,ddrc); asm(mov !portc,w );
    portc = buffer;
    cmd = 0;
    break;

    case 0x5B: //if Port D read
    ddrd = 0xff;//make port d all input
    asm(mov w,ddrd); asm(mov !portd,w );
    send( portd );
    cmd = 0;
    strobe_SND();//send now
    break;
    case 0x5C://if Port D write
    ddrd = 0x0;//make port d all output
    asm(mov w,ddrd); asm(mov !portd,w );
    portd = buffer;
    cmd = 0;
    break;

    case 0x5D: //if Port E read
    ddre = 0xff;//make port e all input
    asm(mov w,ddre); asm(mov !porte,w );
    send( porte );
    cmd = 0;
    strobe_SND();//send now
    break;
    case 0x5E: //if Port E write
    ddre = 0x0;//make port e all output
    asm(mov w,ddre); asm(mov !porte,w );
    porte = buffer;
    cmd = 0;
    break;

    case 0xA5: //if Line in command...
    databit = get_portpin(buffer);
    send(databit);
    strobe_SND();//send now
    cmd = 0;
    break;
    case 0xA6: //if Line out command...
    portpin_hilow(buffer, buffer);
    cmd = 0;
    break;
    }//end of Switch()

    }//end of if(tt==16)
    }//end of while(1)
    }//end of main()




    //********************************************************************/
    void receive_packet()
    {
    rptr = &buffer;
    for(pn=0; pn<10; pn++)
    {
    *rptr = 0xcc;
    rptr++;
    }

    num_bytes=read_usb();//get the number of bytes
    buffer[noparse][[/noparse]0]=num_bytes;
    save_bytes = num_bytes;//save a copy
    pos=1;

    rptr = &buffer;
    while(num_bytes--)
    {
    rptr++;
    empty=1;
    while(empty)//wait for the next byte to arrive
    {
    asm(mov w,porta); asm(mov empty,w); empty &= 0x08; //read RXF
    }

    pn = read_usb();
    *rptr = pn;
    }

    checksum=0;
    rptr = &buffer;
    for(pn=0; pn<save_bytes+1; pn++)
    {
    pos = *rptr;
    checksum = checksum ^ pos;
    rptr++;
    }

    empty=1;
    while(empty)//wait for the next byte to arrive
    {
    asm(mov w,porta); asm(mov empty,w); empty &= 0x08; //read RXF
    }
    if(read_usb() == checksum)//if checksums match
    {
    delay_msec(5);

    asm(mov w,porta); asm(mov empty,w); empty &= 0x08; //read RXF
    if(empty==0)//if more data in FIFO
    {
    //still have data in the FIFO -- ERROR!
    delay_msec(5);

    while(empty==0)//clear the FIFO
    {
    delay_msec(5);
    read_usb();
    asm(mov w,porta); asm(mov empty,w); empty &= 0x08; //read RXF
    }

    send(0xAb);//error!
    packet_ready=0;
    }
    else
    {
    send(0x55);//no error
    delay_msec(5);
    packet_ready=1;
    }
    }
    else//checksum failed
    {
    send(0xaa);//error!
    packet_ready=0;
    }

    strobe_SND();//send now

    }



    //***********************************************************
    toggle_led()
    {
    led_count1++;
    if(led_count1 < 5)
    return;

    led_count1=0;

    led_count++;
    rr=50000;
    if(led_count > rr)
    {
    led_count=0;

    //toggle LED
    if(led_state==0)
    {
    led_state=1;
    asm(clrb portb.5);
    }
    else
    {
    led_state=0;
    asm(setb portb.5);
    }
    }
    }


    //**************************************************
    int get_portpin(int port_pin)
    {
    switch(port_pin)
    {
    case 0xB0: asm(setb ddrb.0); asm(mov w,ddrb); asm(mov !portb,w );
    asm(mov w,portb.0); asm(mov indata,w);
    break;
    case 0xB1: asm(setb ddrb.1); asm(mov w,ddrb); asm(mov !portb,w );
    asm(mov w,portb.1); asm(mov indata,w); indata >>=1;
    break;
    case 0xB2: asm(setb ddrb.2); asm(mov w,ddrb); asm(mov !portb,w );
    asm(mov w,portb.2); asm(mov indata,w); indata >>=2;
    break;
    case 0xB3: asm(setb ddrb.3); asm(mov w,ddrb); asm(mov !portb,w );
    asm(mov w,portb.3); asm(mov indata,w); indata >>=3;
    break;
    case 0xC0: asm(setb ddrc.0); asm(mov w,ddrc); asm(mov !portc,w );
    asm(mov w,portc.0); asm(mov indata,w);
    break;
    case 0xC1: asm(setb ddrc.1); asm(mov w,ddrc); asm(mov !portc,w );
    asm(mov w,portc.1); asm(mov indata,w); indata >>=1;
    break;
    case 0xC2: asm(setb ddrc.2); asm(mov w,ddrc); asm(mov !portc,w );
    asm(mov w,portc.2); asm(mov indata,w); indata >>=2;
    break;
    case 0xC3: asm(setb ddrc.3); asm(mov w,ddrc); asm(mov !portc,w );
    asm(mov w,portc.3); asm(mov indata,w); indata >>=3;
    break;
    case 0xC4: asm(setb ddrc.4); asm(mov w,ddrc); asm(mov !portc,w );
    asm(mov w,portc.4); asm(mov indata,w); indata >>=4;
    break;
    case 0xC5: asm(setb ddrc.5); asm(mov w,ddrc); asm(mov !portc,w );
    asm(mov w,portc.5); asm(mov indata,w); indata >>=5;
    break;
    case 0xC6: asm(setb ddrc.6); asm(mov w,ddrc); asm(mov !portc,w );
    asm(mov w,portc.6); asm(mov indata,w); indata >>=6;
    break;
    case 0xC7: asm(setb ddrc.7); asm(mov w,ddrc); asm(mov !portc,w );
    asm(mov w,portc.7); asm(mov indata,w); indata >>=7;
    break;
    case 0xD0: asm(setb ddrd.0); asm(mov w,ddrd); asm(mov !portd,w );
    asm(mov w,portd.0); asm(mov indata,w);
    break;
    case 0xD1: asm(setb ddrd.1); asm(mov w,ddrd); asm(mov !portd,w );
    asm(mov w,portd.1); asm(mov indata,w); indata >>=1;
    break;
    case 0xD2: asm(setb ddrd.2); asm(mov w,ddrd); asm(mov !portd,w );
    asm(mov w,portd.2); asm(mov indata,w); indata >>=2;
    break;
    case 0xD3: asm(setb ddrd.3); asm(mov w,ddrd); asm(mov !portd,w );
    asm(mov w,portd.3); asm(mov indata,w); indata >>=3;
    break;
    case 0xD4: asm(setb ddrd.4); asm(mov w,ddrd); asm(mov !portd,w );
    asm(mov w,portd.4); asm(mov indata,w); indata >>=4;
    break;
    case 0xD5: asm(setb ddrd.5); asm(mov w,ddrd); asm(mov !portd,w );
    asm(mov w,portd.5); asm(mov indata,w); indata >>=5;
    break;
    case 0xD6: asm(setb ddrd.6); asm(mov w,ddrd); asm(mov !portd,w );
    asm(mov w,portd.6); asm(mov indata,w); indata >>=6;
    break;
    case 0xD7: asm(setb ddrd.7); asm(mov w,ddrd); asm(mov !portd,w );
    asm(mov w,portd.7); asm(mov indata,w); indata >>=7;
    break;
    case 0xE0: asm(setb ddre.0); asm(mov w,ddre); asm(mov !porte,w );
    asm(mov w,porte.0); asm(mov indata,w);
    break;
    case 0xE1: asm(setb ddre.1); asm(mov w,ddre); asm(mov !porte,w );
    asm(mov w,porte.1); asm(mov indata,w); indata >>=1;
    break;
    case 0xE2: asm(setb ddre.2); asm(mov w,ddre); asm(mov !porte,w );
    asm(mov w,porte.2); asm(mov indata,w); indata >>=2;
    break;
    case 0xE3: asm(setb ddre.3); asm(mov w,ddre); asm(mov !porte,w );
    asm(mov w,porte.3); asm(mov indata,w); indata >>=3;
    break;
    case 0xE4: asm(setb ddre.4); asm(mov w,ddre); asm(mov !porte,w );
    asm(mov w,porte.4); asm(mov indata,w); indata >>=4;
    break;
    case 0xE5: asm(setb ddre.5); asm(mov w,ddre); asm(mov !porte,w );
    asm(mov w,porte.5); asm(mov indata,w); indata >>=5;
    break;
    case 0xE6: asm(setb ddre.6); asm(mov w,ddre); asm(mov !porte,w );
    asm(mov w,porte.6); asm(mov indata,w); indata >>=6;
    break;
    case 0xE7: asm(setb ddre.7); asm(mov w,ddre); asm(mov !porte,w );
    asm(mov w,porte.7); asm(mov indata,w); indata >>=7;
    break;
    }

    indata &= 1;
    return indata;
    }



    //*************************************************************
    void portpin_hilow(int port_pin, int hilow)
    {
    switch(port_pin)
    {
    case 0xB0: asm(clrb ddrb.0); asm(mov w,ddrb); asm(mov !portb,w );
    if(hilow) asm(setb portb.0); else asm(clrb portb.0);
    break;
    case 0xB1: asm(clrb ddrb.1); asm(mov w,ddrb); asm(mov !portb,w );
    if(hilow) asm(setb portb.1); else asm(clrb portb.1);
    break;
    case 0xB2: asm(clrb ddrb.2); asm(mov w,ddrb); asm(mov !portb,w );
    if(hilow) asm(setb portb.2); else asm(clrb portb.2);
    break;
    case 0xB3: asm(clrb ddrb.3); asm(mov w,ddrb); asm(mov !portb,w );
    if(hilow) asm(setb portb.3); else asm(clrb portb.3);
    break;
    case 0xB5: asm(clrb ddrb.5); asm(mov w,ddrb); asm(mov !portb,w );
    if(hilow) asm(setb portb.5); else asm(clrb portb.5);
    break;
    case 0xC0: asm(clrb ddrc.0); asm(mov w,ddrc); asm(mov !portc,w );
    if(hilow) asm(setb portc.0); else asm(clrb portc.0);
    break;
    case 0xC1: asm(clrb ddrc.1); asm(mov w,ddrc); asm(mov !portc,w );
    if(hilow) asm(setb portc.1); else asm(clrb portc.1);
    break;
    case 0xC2: asm(clrb ddrc.2); asm(mov w,ddrc); asm(mov !portc,w );
    if(hilow) asm(setb portc.2); else asm(clrb portc.2);
    break;
    case 0xC3: asm(clrb ddrc.3); asm(mov w,ddrc); asm(mov !portc,w );
    if(hilow) asm(setb portc.3); else asm(clrb portc.3);
    break;
    case 0xC4: asm(clrb ddrc.4); asm(mov w,ddrc); asm(mov !portc,w );
    if(hilow) asm(setb portc.4); else asm(clrb portc.4);
    break;
    case 0xC5: asm(clrb ddrc.5); asm(mov w,ddrc); asm(mov !portc,w );
    if(hilow) asm(setb portc.5); else asm(clrb portc.5);
    break;
    case 0xC6: asm(clrb ddrc.6); asm(mov w,ddrc); asm(mov !portc,w );
    if(hilow) asm(setb portc.6); else asm(clrb portc.6);
    break;
    case 0xC7: asm(clrb ddrc.7); asm(mov w,ddrc); asm(mov !portc,w );
    if(hilow) asm(setb portc.7); else asm(clrb portc.7);
    break;
    case 0xD0: asm(clrb ddrd.0); asm(mov w,ddrd); asm(mov !portd,w );
    if(hilow) asm(setb portd.0); else asm(clrb portd.0);
    break;
    case 0xD1: asm(clrb ddrd.1); asm(mov w,ddrd); asm(mov !portd,w );
    if(hilow) asm(setb portd.1); else asm(clrb portd.1);
    break;
    case 0xD2: asm(clrb ddrd.2); asm(mov w,ddrd); asm(mov !portd,w );
    if(hilow) asm(setb portd.2); else asm(clrb portd.2);
    break;
    case 0xD3: asm(clrb ddrd.3); asm(mov w,ddrd); asm(mov !portd,w );
    if(hilow) asm(setb portd.3); else asm(clrb portd.3);
    break;
    case 0xD4: asm(clrb ddrd.4); asm(mov w,ddrd); asm(mov !portd,w );
    if(hilow) asm(setb portd.4); else asm(clrb portd.4);
    break;
    case 0xD5: asm(clrb ddrd.5); asm(mov w,ddrd); asm(mov !portd,w );
    if(hilow) asm(setb portd.5); else asm(clrb portd.5);
    break;
    case 0xD6: asm(clrb ddrd.6); asm(mov w,ddrd); asm(mov !portd,w );
    if(hilow) asm(setb portd.6); else asm(clrb portd.6);
    break;
    case 0xD7: asm(clrb ddrd.7); asm(mov w,ddrd); asm(mov !portd,w );
    if(hilow) asm(setb portd.7); else asm(clrb portd.7);
    break;
    case 0xE0: asm(clrb ddre.0); asm(mov w,ddre); asm(mov !porte,w );
    if(hilow) asm(setb porte.0); else asm(clrb porte.0);
    break;
    case 0xE1: asm(clrb ddre.1); asm(mov w,ddre); asm(mov !porte,w );
    if(hilow) asm(setb porte.1); else asm(clrb porte.1);
    break;
    case 0xE2: asm(clrb ddre.2); asm(mov w,ddre); asm(mov !porte,w );
    if(hilow) asm(setb porte.2); else asm(clrb porte.2);
    break;
    case 0xE3: asm(clrb ddre.3); asm(mov w,ddre); asm(mov !porte,w );
    if(hilow) asm(setb porte.3); else asm(clrb porte.3);
    break;
    case 0xE4: asm(clrb ddre.4); asm(mov w,ddre); asm(mov !porte,w );
    if(hilow) asm(setb porte.4); else asm(clrb porte.4);
    break;
    case 0xE5: asm(clrb ddre.5); asm(mov w,ddre); asm(mov !porte,w );
    if(hilow) asm(setb porte.5); else asm(clrb porte.5);
    break;
    case 0xE6: asm(clrb ddre.6); asm(mov w,ddre); asm(mov !porte,w );
    if(hilow) asm(setb porte.6); else asm(clrb porte.6);
    break;
    case 0xE7: asm(clrb ddre.7); asm(mov w,ddre); asm(mov !porte,w );
    if(hilow) asm(setb porte.7); else asm(clrb porte.7);
    break;
    }
    }


    //Read a byte from the DS18S20
    //**********************************************************************

    unsigned int Read_byte()

    {
    unsigned int data;
    int count;

    data=0;
    for(count=8; count>0; count--)
    {
    //Write the bit to the port
    portpin_hilow(d_pin, 0);

    delay_usec(2);

    //Release port for reading
    get_portpin(d_pin);

    //delay to center of timeslot
    delay_usec(10);


    //Read the data bit in
    D_Data=get_portpin(d_pin);

    //Finish the timeslot
    delay_usec(60);

    //Put data into the byte
    data = data >> 1; //Shift previous bits across
    if(D_Data==1) //If data was high then add high bit to data
    data +=0x80;

    //Delay Between Bits
    delay_usec(10);
    }

    //rise time plus min space
    delay_usec(10);

    return(data);
    }






    //**********************************************************************
    void D_Reset() //Reset the DS18S20
    {
    int count;

    D_Error=99; //-- Reset the status bit to no error

    get_portpin(d_pin);

    //Start the reset Pulse
    portpin_hilow(d_pin, 0);

    delay_usec(80);
    delay_usec(200);
    delay_usec(200);

    //release the line
    get_portpin(d_pin);

    //delay to about the center of the presence pulse
    delay_usec(90);

    //get presence status 1=fail 0=present
    D_Presence = get_portpin(d_pin);

    delay_usec(100);
    delay_usec(200);

    D_SC = get_portpin(d_pin);//check for short circuit

    if(D_SC == 0) //if short circuit then error
    D_Error = 8;

    if(D_Presence == 1) //if no device detected then error
    D_Error = 2;

    delay_usec(10);
    }



    //**********************************************************************
    void Write_byte(int Data)//write a byte to the DS18S20
    {
    int count;

    for(count=8; count>0; count--)
    {
    D_Data= Data & 0x01; //LSB

    //write the bit to the port
    portpin_hilow(d_pin, 0);

    delay_usec(4); //time slot start

    //write data to the port
    if(D_Data)
    get_portpin(d_pin);//input (pulled high)
    else
    portpin_hilow(d_pin, 0);//driven low

    delay_usec(66);

    //release port pin
    get_portpin(d_pin);

    delay_usec(10);

    Data>>=1; //shift next bit into place
    }

    delay_usec(10);
    }




    //********************************************************************/
    void strobe_SND()
    {
    asm(clrb portb.4);
    asm(nop);
    asm(nop);
    asm(nop);
    asm(nop);
    asm(setb portb.4);
    }


    //********************************************************************/
    void send(int thebyte)
    {
    //send the byte back through the USB interface
    SETPORTDOUT;//set data direction to output

    //when TXE is high do not write
    FIFO_busy=1;
    while(FIFO_busy)
    {
    asm(mov w,porta); asm(mov FIFO_busy,w); FIFO_busy &= 0x04; //read TXE
    }

    portd = thebyte;//put data on the bus
    delay_usec(10);
    asm(clrb porta.1);//A1 low - WR low
    delay_usec(10);
    asm(setb porta.1);//A1 high - WR high

    portd = 0;
    SETPORTDIN;
    }


    //********************************************************************/
    unsigned int read_usb()
    {
    rempty=1;
    while(rempty)//while A3 (RXF) is high (no data received)
    {
    asm(mov w,porta); asm(mov rempty,w); rempty &= 0x08; //read RXF
    }

    SETPORTDIN;//set data direction to input
    asm(clrb porta.0);//A0 low - RD# low
    delay_usec(10);
    data8 = portd;//read databus
    asm(setb porta.0);//A0 high - RD# high

    return data8;
    }


    //********************************************************
    void delay_msec(unsigned int msec)
    {
    asm(clr !wdt);//pet the dog

    while(msec--)
    {
    //pause for 1 millisecond
    delay_usec(250);
    delay_usec(250);
    delay_usec(250);
    delay_usec(250);
    }
    }


    //********************************************************
    void delay_usec(unsigned int usec)
    {
    while(usec--)
    {
    xloop=3;
    while(xloop--);
    asm(nop);
    asm(nop);
    asm(nop);
    asm(nop);
    asm(nop);
    asm(nop);
    asm(nop);
    asm(nop);
    }
    }
  • ElectronegativityElectronegativity Posts: 311
    edited 2007-09-20 21:21
    I am at work right now and can't get through all of it.

    Is port D connected to anything on the board, or just pinned out to a header?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    I wonder if this wire is hot...
  • GOTigerGOTiger Posts: 4
    edited 2007-09-20 21:51
    Pinned out which I use voltage meter to check.
  • GOTigerGOTiger Posts: 4
    edited 2007-09-20 21:53
    Actually I found out only Databus Port D changed to High when other Ports change. But Port B, C, E data will not change along with other Ports change.
Sign In or Register to comment.