Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

What is wrong about the interruption of my NAT7210?

void gpib_init() //chip initialization { outp(5,0X02); //chip reset outp(5,0X2A); //set clock 20MHz outp(5,0X50); //page_in outp(3,0X80); //set ICR2 outp(4,0X31); //set ADMR outp(6,0X2F); //set gpib address is 15 outp(6,0XCF); outp(3,0X00); //initial serial poll response outp(5,0XE0); //initial parallel response outp(5,0XB4); outp(5,0X4B); outp(5,0X8C); outp(1,0X13); //interrupt enable outp(2,0X40); outp(5,0X00); //pon } void intr _INT3Interrupt(void) //INT3 { IEC3bits.INT3IE=0; IFS3bits.INT3IF=0; nStatus=inp(0); //read ISR0 if(nStatus&0X80) { if(inp(1)&0X04) { MyStatus=inp(2); if(MyStatus&0X02) //talker,set state { bListen=0; bTalk=1; } if(MyStatus&0X04) //listener,set state { bListen=1; bTalk=0; } } } if((nStatus&0X20)&&(bListen==1)) //receive new data { DataRcv=inp(7); pdtem_r[nRCount++]=DataRcv; //take data to buffer outp(3,0X02); // complete receiving data } if((nStatus&0X10)&&(bTalk==1)) //last data sending completly { if(!bSndOver) //buffer is blank or not { DataSnd=remote[nSCount++]; //if(nSCount==nSNumber) if(remote[nSCount]==0X0A) { outp(3,0X08); //send EOI bSndOver=1; //send completly } outp(7,DataSnd); //send next data } } if(nStatus&0X80) { bRecOver=1; //receive the string of data completly,set state } if(nStatus&0X04) { outp(5,0X40); } IEC3bits.INT3IE=1; IFS3bits.INT3IF=0; } I use the NAT7210 which is controlled by MCU. This is my program,after gpib_init( ), the level of the pin 11 is low all along. But I think it should be high. And I think, if there is data which is transmitted to NAT7210 from PC, the IC should generate an interruption and the level of the pin 11 should be changed from high to low, and immediately it will be from low to high. If it is from high to low, my MCU will go to INT3Interrupt. But no interruption is generated when data is transmitted. Please give me a help and check if my codes is correct. Thanks!
0 Kudos
Message 1 of 13
(4,745 Views)

Hello,

 

Please format your post so that it is readable.  Right now, I am unable to figure out what is going wrong because I can't tell where the comment symbols end.

 

Thanks,

Steven T.

0 Kudos
Message 2 of 13
(4,728 Views)

reposted here

 

You did not need to create a new post. All you had to do was add a reply to this one. Please keep all discussion in the new post.

0 Kudos
Message 3 of 13
(4,721 Views)
void gpib_init() //chip initialization
{
outp(5,0X02); //chip reset
outp(5,0X2A); //set clock 20MHz
outp(5,0X50); //page_in
outp(3,0X80); //set ICR2
outp(4,0X31); //set ADMR
outp(6,0X2F); //set gpib address is 15
outp(6,0XCF);
outp(3,0X00); //initial serial poll response
outp(5,0XE0); //initial parallel response
outp(5,0XB4);
outp(5,0X4B);
outp(5,0X8C);
outp(1,0X13); //interrupt enable
outp(2,0X40);
outp(5,0X00); //pon
}
void intr _INT3Interrupt(void) //INT3
{
IEC3bits.INT3IE=0;
IFS3bits.INT3IF=0;
nStatus=inp(0); //read ISR0
if(nStatus&0X80)
{
if(inp(1)&0X04)
{
MyStatus=inp(2);
if(MyStatus&0X02) //talker,set state
{
bListen=0;
bTalk=1;
}
if(MyStatus&0X04) //listener,set state
{
bListen=1;
bTalk=0;
}
}
}
if((nStatus&0X20)&&(bListen==1)) //receive new data
{
DataRcv=inp(7);
pdtem_r[nRCount++]=DataRcv; //take data to buffer
outp(3,0X02); // complete receiving data
}
if((nStatus&0X10)&&(bTalk==1)) //last data sending completly
{
if(!bSndOver) //buffer is blank or not
{
DataSnd=remote[nSCount++];
//if(nSCount==nSNumber)
if(remote[nSCount]==0X0A)
{
outp(3,0X08); //send EOI
bSndOver=1; //send completly
}
outp(7,DataSnd); //send next data
}
}
if(nStatus&0X80)
{
bRecOver=1; //receive the string of data completly,set state
}
if(nStatus&0X04)
{
outp(5,0X40);
}
IEC3bits.INT3IE=1;
IFS3bits.INT3IF=0;
}
I use the NAT7210 which is controlled by MCU.
This is my program,after gpib_init( ), the level of the pin 11 is low all along.
But I think it should be high.
And I think, if there is data which is transmitted to NAT7210 from PC, the IC should generate an interruption and the level of the pin 11 should be changed from high to low,
and immediately it will be from low to high.
If it is from high to low, my MCU will go to INT3Interrupt.
But no interruption is generated when data is transmitted.
Please give me a help and check if my codes is correct.
Thanks!
0 Kudos
Message 4 of 13
(4,714 Views)

Hello Fujun,

 

I found a few small mistakes that could have made things not work very well.

 

1.  Step one in initialization is to make sure that the 7210 is in 7210 mode.  How are you insuring this?  I just want to make sure this is accounted for.

 

2.  In gpib_init() Set clock to 20MHz

 

I see that you are writing ICR correctly, however there is a problem when writing ICR2.  20 MHz requires that the MICR bit is set.  When writing 0x80, this bit is cleared....so the correct value to write to ICR2 is 0x81

 

3.  When configuring the GPIB Address, you set ADR0 to have listening disabled on address 15, then you set ADR1 to have talking disabled on address 15.  I would recommend instead to enable both listening and talking on address 15 (ADR0) and completely disable a second address on ADR1.

 

outp(6,0x0F)

outp(6,0xE0)

 

After I found these two problems (plus my first question), I stopped verifying your routine, since these errors would be enough to stop communication from happening.

 

Let me know if correcting these issues does not help.  Another posting of your code would be helpful.

 

Steven T.

0 Kudos
Message 5 of 13
(4,687 Views)
Hello Steven T,
Your advice is helpful,I have already rejiggered my program according to your advice . And if I send message from PC to my AT7210,I can read 0X01 from ISR1,then I receive the message successfully in INT3 of MCU .
But another problem appears . When PC wants to get data and it sends command to tell NAT7210 its idea . I think,at this time,NAT7210 should generate interrupt also,and then I can read 0X02 from ISR1 . But at this case,NAT7210 dose not generate interrupt .
Following is my program,

void gpib_init() //NAT7210 initialization
{
outp(5,0X02); //chip reset
outp(3,0X99); //make sure NAT7210 work in 7210-mode
outp(5,0X50); //Page_in
outp(3,0X81); //ICR2
outp(5,0X2A); //ICR //set clock 20MHz
outp(4,0X31); //ADMR
outp(6,0X0F); //set NAT7210 address:15
outp(6,0XE0);
outp(5,0XA8); //set interrupt level:low
outp(3,0X00); //SPMR
outp(5,0XE0); //AUXRI:USTD is 0
outp(5,0XB4); //AUXRB:ISS is 1,TRI is 1
outp(5,0X4B); //set AUXRG:CHES,NTNL
outp(5,0X8C); //set AUXRA , RFD Holdoff on END Mode
outp(1,0X13); //interrupt enable
outp(2,0X40);
outp(7,0X0A); //0X0A
outp(5,0X00); //pon
}

void intr _INT3Interrupt(void) //INT3
{
uchar tem88,tem48,i;
IEC3bits.INT3IE=0;
IFS3bits.INT3IF=0;
for(i=0;i<50;i++)
pdtem_r[i]=0;
i=0;

nStatus=inp(1); //read ISR1
if((nStatus&0X01)==0X01) //listenner,receive data
{
tem88=inp(0);
while(tem88!=0x0a)
{
pdtem_r[i]=inp(0);
i++;
tem48=inp(1);
while((inp(1)&0X01)!=0x01);
tem88=inp(0);
}
pdtem_r[i]=0x0a;
}
else if((nStatus&0X01)==0X02) //talker,send data
{
ProcessData();
}
IEC3bits.INT3IE=1;
IFS3bits.INT3IF=0;
}

Please give me a help and check if my codes is correct.
Thanks!
0 Kudos
Message 6 of 13
(4,676 Views)

Hello mxzh,

 

I found one more issue.

 

  • You write auxrb twice.  The first access, your program sets the polarity of the interrupt line.  On the second access, you set other bits and set the polarity to the opposite of what was set before.

I also think that you are expecting the chip to automatically read data from the GPIB and let you know that it has data.  In actuality, there is a whole list of steps that must happen before you get a message.  Please check out Sending GPIB Data Messages in the manual.  The first step is to see that the controller has addressed the NAT7210 as talker, then it must manually send the data out.  The same steps must take place for receiving data.

 

One interrupt that should be seen is the ADSC line in ISR2.  This will let you know that your addressing has changed.  If the other interrupt bits are set correctly, this should result in the INT hardware line changing state.

 

Thanks,

Steven T.

0 Kudos
Message 7 of 13
(4,653 Views)
Hello Steven T,
I have corrected my code according to your advice . And I have read Sending GPIB Data Messages in the manual , flowing is the code for setting NAT7210 . I can let the chip as a listener successfully . When GPIB sends data , the state of INT line will change then MCU responds it immediately .
But when GPIB sends command to let NAT7210 as a talker and receive message from NAT7210 , the state of INT line is high all along .
Please help me , I am not good at English so I possibly understand of the manual incompletely .
Thanks very much .

void gpib_init() //NAT7210 initialization
{ outp(5,0X02); //chip reset
outp(3,0X99); //make sure NAT7210 work in 7210-mode
outp(5,0X50); //Page_in
outp(3,0X81); //ICR2
outp(5,0X2A); //ICR //set clock 20MHz
outp(4,0X31); //ADMR
outp(6,0X0F); //set NAT7210 address:15
outp(6,0XE0);

outp(3,0X00); //SPMR
outp(5,0XE0); //AUXRI:USTD is 0
outp(5,0XB4); //AUXRB:ISS is 1,TRI is 1
outp(5,0X4B); //set AUXRG:CHES,NTNL
outp(5,0X8C); //set AUXRA , RFD Holdoff on END Mode
outp(1,0X13); //interrupt enable
outp(2,0X40);
outp(7,0X0A); //0X0A
outp(5,0X00); //pon
}
0 Kudos
Message 8 of 13
(4,641 Views)
Hello Steven T,
Please help me check my codes . I have read the manual ,but I can not find any mistakes in my codes . Please teach me .
Thank you very much .
Fujun
0 Kudos
Message 9 of 13
(4,610 Views)

Hello,

 

Sorry for the delay in replying.  I was on vacation some of last week and this week.

 

You don't seem to be checking for th ADSC bit in the ISR2 register.  This bit will set as soon as the GPIB controller addresses the NAT7210 as talker or listener.  If this bit is set, it should generate an interrupt if the other interrupt bits are set correctly (GLINT bit in ISR0 must be set).  The interrupt will tell you when you can start the transfer by using the DIR and CDOR registers.

 

Would it be possible to see what happens when your code detects the change in addressing?  Also what happens when you attempt to send/receive data?

 

Thanks,

Steven T.

0 Kudos
Message 10 of 13
(4,554 Views)