Using following code for initialization of GPIB interface:
//=============================================================
#define WriteTNT(cAddr, cData) \
{ \
LATF = (LATF & 0xe0) | (cAddr & 0x1f); /*set addr on RA0-RA4*/ \
LATD = cData; \
CSNLO; \
WRNLO; \
WRNHI; \
CSNHI; \
}
void InitGPIB(void)
{
//0. TNT Hardware RESET
LATCbits.LATC5 = 0; //TNT hardware reset
LATFbits.LATF5 = 1; //set TNT startup mode to Turbo+7210/One-chip
Nop();
Nop();
Nop();
Nop();
LATCbits.LATC5 = 1; //clear TNT reset state
Nop();
Nop();
Nop();
Nop();
//1. Reset the Turbo488 Circuitry of the TNT4882
WriteTNT(_T488_CMDR, SOFT_RESET); //Comand Register = 0x22 - SOFT RESET
//2. Place the TNT4882 in Turbo+7210 Mode
WriteTNT(0x06,0x80);
WriteTNT(0x0a,0x80);
WriteTNT(0x06,0x99);
WriteTNT(0x0a,0x99);
//3. Configure the TNT4882 for One-Chip Mode
WriteTNT(_T488_HSSEL, 1); //Switch TNT to One-Chip mode (ONEC = 1)
//4. Make Sure that the Local Power-On Message is Asserted
WriteTNT(_7210_AUXMR, 2); //Local Power-On Message is Asserted
WriteTNT(_7210_KEYREG, 0); //clear the swap bit
WriteTNT(_7210_EOSR, 0x0a); //EOS = 0x0a (not used, but initalizing)
//WriteTNT(_7210_CDOR, 0); //clear data lines -- Do not use the CDOR in one-chip mode
//5. Configure the TNT4882 for GPIB Operation
//A. Set the GPIB Address(es)
/*!!!NRFD is becoming LOW after that command!!!*/WriteTNT(_7210_ADMR, 0x31); //set dual primary addressing mode
WriteTNT(_7210_ADR, g_GPIB_ADDR); //primary address
WriteTNT(_7210_ADR, 0xe0); //no secondary address => E0
//B. Write the Initial Serial Poll Response
WriteTNT(_7210_SPMR, 0x8f); //Serial poll 10001111
//C. Configure the Initial Parallel Response
WriteTNT(_7210_AUXMR,0x70); //Using remote configuration 01110000
//D. Setup Interrupts
WriteTNT(_7210_IMR0,0); //disable all interrupts
WriteTNT(_7210_IMR1,0);
WriteTNT(_7210_IMR2,0);
WriteTNT(_T488_IMR3,0);
//E. Set the GPIB Handshake Parameters
WriteTNT(_7210_HIER, 0xc0); //DGA DGB - handshake parameters 11000000
WriteTNT(_T488_CNT0,0); //Verify every other bit can be set
WriteTNT(_T488_CNT1,0);
WriteTNT(_7210_AUXMR,0xa4);
WriteTNT(_7210_AUXMR,0x8c);
WriteTNT(_T488_CMDR,RESET_FIFO); //send RESET_FIFO command
WriteTNT(_7210_AUXMR,0x88);
//6. Clear the Local Power-On Message to Begin GPIB Operation
WriteTNT(_7210_AUXMR,0);
ListenGPIB(); //switch TNT to listener mode
DATAIN_TNT;
}
void ListenGPIB(void)
{
//switching TNT to listener mode
WriteTNT(_T488_CMDR, RESET_FIFO);
WriteTNT(_T488_CFG, 0x28);
WriteTNT(_T488_CNT0, GPIB_BYTES_EXPECT); //how much bytes are we expect
WriteTNT(_T488_CNT1, 0xff);
WriteTNT(_7210_IMR1, 0); //set up interupts
WriteTNT(_7210_IMR2, 0);
WriteTNT(_7210_IMR0, 0x80);
WriteTNT(_T488_IMR3, 4);
WriteTNT(_T488_CMDR, GO);
}
void main()
{
.
.
.
g_GPIB_ADDR = 1;
InitGPIB();
for( ; ; );
.
.
.
}
//======================================================
Code is written, according to TNT4882 datasheet. Using 40 MHz for TNT clock and 20 MHz PIC clock. It works on another board with completely identical design, when TNT clock is ~60 MHz(although have problems when <40MHz - sometimes stops working). It was detected some difference after initialization of that board and other GPIB instruments. Devices that working have NRFD = HIGH after initialization, but on our board NRFD goes to LOW after writing 31(hex) to ADMR. It's possible that something happened with hardware, maybe some part of TNT is damaged, because tested similar initialization code on another board (it has almost identical design to our board, it's using common clock = 4 MHz for PIC and TNT, and there are some NOPs when writing to TNT), and it works. Also detected that, if disconnecting clock from TNT, then turn on power of PIC, then turn on clock of TNT after delay (don't know good delay value, something about ~500 ms), sometimes it starts working, but very rarely. How can I check, that TNT controller hardware is OK (maybe some registers, pins etc.)?
Thanks.
Message Edited by NoAngel on 03-13-2007 12:11 PM
--
Best Regards,
NoAngel