CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Multiple PIC communication
Goto page Previous  1, 2, 3
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
neverlog



Joined: 02 May 2010
Posts: 36

View user's profile Send private message

PostPosted: Thu Aug 12, 2010 9:29 pm     Reply with quote

Dear All,

in the ex_PBUSM.c example, in line 71.

#bit intf=11.1

May I know what is this line means?

Thank you very much on your help.

I really appreciate the help. Thanks!!
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Fri Aug 13, 2010 7:48 am     Reply with quote

Well, I'm agree with you that some examples there are not so good documented as one expect and some
lines of code is hidden behind an abstraction, like: #bit intf=11.1
If you look at in the Microchip MCU datasheets, you will note that intf is the name of bit 1 of the INTCON
Register, this apply to all midrange MCUs, where the Registers names and its bits Position names, are the same.

See the PIC16F877 datasheet, P.15
TABLE 2-1: SPECIAL FUNCTION REGISTER SUMMARY On Bank0, at the address 0x0B you will see the
INTCON Reg, hence: #bit intf=11.1 // has the same meaning in decimal notation.

Regarding your previous question:
Quote:

Does anyone know what is PBUS_NEED_CS=0x84 using for?

It is also undocumented info, it is an implementation of One-wire communication.
The example use some concepts from LIN protocol, that is an open collector driver line and, being a
Master/Slave protocol, both handle the transfer of information, hence it is necesary a tight protocol in order
to arbitrate how to handle an unique communication line. In the LIN protocol there are defined only one
command: SLEEP (command code 0x80) and CCS use the command line PBUS_IDLE=0x80 with the same efect.
The LIN Protocol Specification does not define the content of each message (except for the SLEEP),
hence command like PBUS_NEED_LEN=0x81,PBUS_NEED_TO=0x82, PBUS_NEED_FROM=0x83,
PBUS_NEED_CS=0x84 can be freely created/used according with the applications needs.
All the previous comments regarding ex_pbus.c and the relation with LIN are my own conclusion, I would
appreciate corrections from somebody that had been putting your hand in this stuff and/or have a better
info to share, will be welcome to enrich the forum.

Humberto
neverlog



Joined: 02 May 2010
Posts: 36

View user's profile Send private message

PostPosted: Mon Aug 16, 2010 8:57 am     Reply with quote

Thank you Humberto for your kind sharing.

It helps me look into this matter from different perspective. Thanks!
neverlog



Joined: 02 May 2010
Posts: 36

View user's profile Send private message

PostPosted: Thu Aug 19, 2010 3:08 am     Reply with quote

Dear All,

I have study the whole code for ex_PBUSM.c

I have modify the program, but the master just won't receive the data send by slave. My compiler is 4.104. I have debugged for 2 days. I just can't figure why. Anyone please help me! I am going nuts....

Slave code(Transmitting data)
Code:

#include <18F4520.h>
#fuses hs,noprotect,nowdt,nolvp,BROWNOUT
#use delay(clock=20000000) //40mhz
#use rs232(baud=9600, float_high, bits=9, xmit=PIN_B2, rcv=PIN_B2)

//For Multiple MCU Communication=================================
#define OUR_ID 1

#byte porta=5
#byte portb=6
#byte portc=7

#define MAX_LENGTH   7

byte pbus_buffer[MAX_LENGTH+1];
byte start_receive=0;

enum pbus_states {PBUS_IDLE=0x80,PBUS_NEED_LEN=0x81,PBUS_NEED_TO=0x82,
                  PBUS_NEED_FROM=0x83,PBUS_NEED_CS=0x84};
byte pbus_state=PBUS_IDLE;
byte checksum;
byte last_byte;

#bit ninth_bit = RS232_ERRORS.7
#bit collision = RS232_ERRORS.6
#bit intf = 11.1

//Communication Line for Multi-MCU using B2 interrupts=========================


void pbus_send( byte * message, byte to, byte len) {
   byte checksum,i;

   retry:
      checksum=len^OUR_ID^to;
      disable_interrupts(GLOBAL);
      collision=false;
      ninth_bit=1;

      putc(0xf1);           if(collision) goto error;
      putc(to);             if(collision) goto error;
      putc(OUR_ID);         if(collision) goto error;
      putc(len);            if(collision) goto error;
      ninth_bit=0;
      for(i=1;i<=len;++i) {
        checksum^=*message;
        putc(*(message++)); if(collision) goto error;
      }
      putc(checksum);       if(collision) goto error;
      intf=false;
      enable_interrupts(GLOBAL);
      return;

   error:
      delay_ms(16);
      enable_interrupts(GLOBAL);
      goto retry;
}


//main program================================================
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#include <input.c>
void main() {

   byte mychar,yto,ylen,y,msg[MAX_LENGTH];


   
   delay_ms(1000);

   ext_int_edge( h_to_l );
   enable_interrupts(global);
   enable_interrupts(int_ext2);  //enable interrupts on B2

   do {

           output_high(PIN_B7);

            mychar=pbus_buffer[2];

             msg[0]=0x41;
             msg[1]=0x42;
             msg[3]=0x43;
             msg[4]=0x44;
             msg[5]=0x45;
             msg[6]=0x46;
             //msg[7]=0x50;
             //msg[8]=0x48;
         
           yto=0x39;    //9 , Master ID
           ylen=0x38;  //8
           pbus_send(msg,yto,ylen);    //master ID is 16, len is 80
           
           delay_ms(1000);
           output_low(pin_B7);
           delay_ms(1000);
 
   } while(true);
   
}


Master Code(Receiving Data)
Code:

#include <18F4520.h>
#fuses hs,noprotect,nowdt,nolvp,BROWNOUT
#use delay(clock=20000000) //40mhz
#use rs232(baud=9600, float_high, bits=9, xmit=PIN_B2, rcv=PIN_B2)

//For Multiple MCU Communication=================================
#define OUR_ID 9       //master id =16

#define MAX_LENGTH  95

byte pbus_buffer[MAX_LENGTH+1];

byte start_receive=false;
enum pbus_states {PBUS_IDLE=0x80,PBUS_NEED_LEN=0x81,PBUS_NEED_TO=0x82,
                  PBUS_NEED_FROM=0x83,PBUS_NEED_CS=0x84};
byte pbus_state=PBUS_IDLE;
byte checksum;
byte last_byte;

#bit ninth_bit = RS232_ERRORS.7
#bit collision = RS232_ERRORS.6
#bit intf = 11.1

#byte porta=5
#byte portb=6
#byte portc=7

//Communication Line for Multi-MCU using B2 interrupts=========================

#int_ext2
void pbus_isr() {
    byte data;

    if(kbhit()) {

      data=getc();

      if(ninth_bit) {
         switch(pbus_state) {
           case PBUS_IDLE : if(data==0xf1)
                                pbus_state=PBUS_NEED_TO;
                            break;
           case PBUS_NEED_TO :
                            if(data==OUR_ID)
                               pbus_state=PBUS_NEED_FROM;
                            else
                               pbus_state=PBUS_IDLE;
                            checksum=data;
                            break;
           case PBUS_NEED_FROM :
                            pbus_buffer[0] = data;
                            pbus_state=PBUS_NEED_LEN;
                            checksum^=data;
                            break;
           case PBUS_NEED_LEN :
                            last_byte = data+1;
                            pbus_buffer[1] = data;
                            pbus_state=2;
                            checksum^=data;
                            break;
         }
      } else{
        if(pbus_state==PBUS_NEED_CS) {
           if(checksum==data)
               start_receive=true; //next_in = (next_in+1) % MAX_MESSAGES;
           else start_receive=false;
           
           pbus_state=PBUS_IDLE;
        } else if(pbus_state<0x80) {
           pbus_buffer[pbus_state] = data;
           checksum^=data;
           if(++pbus_state>last_byte)
              pbus_state=PBUS_NEED_CS;
      }
      }
    }
}

//main program================================================
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#include <input.c>

void main() {
   byte to,len,i,msg[MAX_LENGTH];
   ext_int_edge( h_to_l );
   enable_interrupts(global);
   enable_interrupts(int_ext2);  //enable interrupts on B2
   
   set_tris_b(0b00000001);
   
   output_low(pin_B6);
   output_low(pin_B7);
   
   delay_ms(500);

   printf("\r\n\Multi MCU-Master Controller V1.0\r\n");
   printf("\r\nReceive Mode ready\r\n");



   do {

      if(start_receive) {              //if checksum ok, then start print data
         //delay_ms(50);
         printf("\r\nData ID from #%d: ",pbus_buffer[0]);
         for(i=2;i<=10;++i){
           printf(" %2X",pbus_buffer[i]);
         }
         
       start_receive=false;
      }

     
   } while(true);
   
}

Please help me! Thanks in advance! Thank you.
neverlog



Joined: 02 May 2010
Posts: 36

View user's profile Send private message

PostPosted: Thu Aug 19, 2010 5:15 am     Reply with quote

I have corrected some bug.

ext_int_edge( 2, h_to_l );
enable_interrupts(int_ext2);

But still can't work.... Please help!
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2, 3
Page 3 of 3

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group