To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.robotics.rcx.legosOpen lugnet.robotics.rcx.legos in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Robotics / RCX / legOS / 4016
4015  |  4017
Subject: 
Re: Success
Newsgroups: 
lugnet.robotics.rcx.legos
Date: 
Tue, 20 May 2008 12:10:51 GMT
Viewed: 
23893 times
  
Hi

I have implemented the stuff
// and set the port6<7> pin LOW. Now the upper PNP transistor isn't conducting
anymore.

Now TX and RX works

Here are the program


#include <lnp.h>
#include <conio.h>
#include <string.h>
#include <lnp-logical.h>
#include <dkey.h>
#include <dsound.h>

#include <sys/lnp-logical.h>
#include <sys/lnp.h>
#include <sys/h8.h>

#include <dkey.h>

#define MY_PORT 2
#define DEST_HOST 0x8
#define DEST_PORT 0x7
#define DEST_ADDR ( DEST_HOST << 4 | DEST_PORT )      // rcx0

#define SENDBUFF 25
unsigned char buf[SENDBUFF];
unsigned char len = 3;
unsigned char receive_buffer[5];

static const note_t rx[] = {
  { PITCH_C5,  1 } , { PITCH_D5,  1 } ,{ PITCH_E5,  1 } ,{ PITCH_END, 0 }
};

wakeup_t prgmKeyCheck(wakeup_t data)
{
    return dkey == KEY_PRGM;
}

/*
void packet_handler_add(const unsigned char* data,unsigned char length, unsigned
char src)
{
// ++rx_count;
}
*/

void baud2400() {

   unsigned short lnp_byte_time      =  MSECS_TO_TICKS(5);          //!< 2400
baud

   unsigned short lnp_byte_timeout   =   (3*lnp_byte_time/2);      //!< timeout waiting for a byte
   unsigned short lnp_byte_safe_temp =   (4*lnp_byte_time);    //!< delay before transmitting a b yte
   unsigned short lnp_wait_txok_temp =   (2*lnp_byte_timeout); //!< delay after good transmit
   unsigned short lnp_wait_coll_temp =   (4*lnp_byte_timeout); //!< delay after collision

   lnp_logical_baud_rate = B2400;
   lnp_logical_parity =    SMR_P_ODD;

   lnp_byte_safe = lnp_byte_safe_temp;
   lnp_wait_txok = lnp_wait_txok_temp;
   lnp_wait_coll = lnp_wait_coll_temp;
}

void baud4800() {

   unsigned short lnp_byte_time = MSECS_TO_TICKS(3);          //!< 4800 baud

   unsigned short lnp_byte_timeout   =   (3*lnp_byte_time/2);      //!< timeout waiting for a byte
   unsigned short lnp_byte_safe_temp =   (4*lnp_byte_time);    //!< delay before transmitting a b yte
   unsigned short lnp_wait_txok_temp =   (2*lnp_byte_timeout); //!< delay after good transmit
   unsigned short lnp_wait_coll_temp =   (4*lnp_byte_timeout); //!< delay after collision

   lnp_logical_baud_rate = B4800;
   lnp_logical_parity =    SMR_P_NONE;

   lnp_byte_safe = lnp_byte_safe_temp;
   lnp_wait_txok = lnp_wait_txok_temp;
   lnp_wait_coll = lnp_wait_coll_temp;
}

    void infrared_on()    {
     //! enable IR carrier frequency.
     //extern inline void carrier_init(void) {  }
     T1_CR  =0x9;
     T1_CSR =0x13;
     T1_CORA=0x1a;
  }

// doesnt work well with usb tower
void infrared_on76khz()    {
     //! enable IR carrier frequency.
     //extern inline void carrier_init(void) {  }
     T1_CR  =0x9;
     T1_CSR =0x13;
     // change it to76 KHz   setting T1_CORA to 0x0D instead of 0x1A.
     T1_CORA=0x0D;
  }

  void infrared_off()      {
//! disable IR carrier frequency.    // carrier_shutdown();
//extern inline void carrier_shutdown(void)
  T1_CR  =0;
  T1_CSR =0;
  }

void packet_handler_integrity(const unsigned char* data,unsigned char length)
{
dsound_system(DSOUND_BEEP);//DSOUND_SYS_MAX
// cputs(data);
}

void SendInt(int i)
{
int result,i;
   for (i=0; i<SENDBUFF; i++ ){
      buf[i]  = 'U';
  }

   buf[0]  = 'A';
   buf[1]  = 'B';
   buf[2]  = 'C';

   // result = lnp_addressing_write( buf, sizeof(buf), DEST_ADDR, MY_PORT);
        result =      lnp_logical_write(   buf, sizeof(buf));

   // result = lnp_integrity_write(data,len);
    // msleep(500);
   // result = lnp_integrity_write( buf, sizeof(buf));

}


int main ( int argc, char **argv )
{
int result,i;
int c=48;

  cputs("down") ;      sleep(1);
  //! Shutdown the logical layer (IR port)
  lnp_logical_shutdown();      sleep(1);

  // change Baudrate to 4800
  cputs("4800") ;      sleep(1);
baud4800();                      sleep(1);

  cputs("init") ;    sleep(1);
  lnp_init();        sleep(1);
  //! Initialize the logical layer (IR port)
  lnp_logical_init();         sleep(1);

// infrared carrier off
//  To correctly use the H8 TX line with the CMUCam2 module,
  // the driving RCX software MUST shut down the 38kHz carrier
cputs("if--") ;      sleep(1);
infrared_off();    sleep(1);

  // and set the port6<7> pin LOW. Now the upper PNP transistor isn't
conducting anymore.
  cputs("pt67") ;      sleep(1);
  cputw(PORT6);        sleep(2);
  cputs("cler") ;      sleep(1);
bit_clear(&PORT6,7);   sleep(1);
cputw(PORT6);        sleep(1);

  cputs("baud") ;                  sleep(2);
  lcd_int(lnp_logical_baud_rate);  sleep(2);


  // lnp_addressing_set_handler_add(MY_PORT, packet_handler_add);
  lnp_integrity_set_handler( packet_handler_integrity);
  //lnp_logical_range (0 );

  cputs("baud") ;        sleep(1);
  lcd_int(lnp_logical_baud_rate);         sleep(1);

  cputs("run") ;      sleep(2);

    while( 1 ) {
          if( prgmKeyCheck( 0 ) ){
             dsound_system(DSOUND_BEEP);//DSOUND_SYS_MAX
             baud2400();  sleep(1);
             bit_set(&PORT6,7); sleep(1);
             infrared_on(); sleep(1);
             break;
        }
        SendInt( c );
        lcd_int(c-48);   msleep(500);
        c++;
        if (c >= 48+10 ) c =48;

      cputs("baud") ;        sleep(1);
       lcd_int(lnp_logical_baud_rate);         sleep(1);
    }
    // infrared_off(); cputs("if--") ;        sleep(3);
    // infrared_on(); cputs("if38") ;        sleep(3);
    cputs ( "done" );
  sleep(2); // show done for 2 sec then clear display...
    lcd_clear();
    return 0;
}


by the way. I have written a DLL for the Infrared Tower based on the C program
called. lnphost

by
Bernhard



Message is in Reply To:
  RCX Serial Hardware Hack
 
Hi As allready described in a other thread i have build a bluetoothconnection between pc and the RCX. There is one thing that the serial bluetooth is only available to tx/rx with a minimum from 4800 baud. At first i compiled brickos 0.9.0 with (...) (16 years ago, 20-May-08, to lugnet.robotics.rcx.legos)

7 Messages in This Thread:




Entire Thread on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact
    

Custom Search

©2005 LUGNET. All rights reserved. - hosted by steinbruch.info GbR