vlad_2770 Postat Decembrie 18, 2009 Partajează Postat Decembrie 18, 2009 Folosesc urmatoarea functie pentru a comunica pe I2C cu un senzor de temperatura TC74. Problema este ca pe un 18F452 merge functia dar pe un PIC18F2550 se blocheaza la pasul 6. Nu-mi dau seama care ar putea sa fie greseala. Si nu stiu de ce din cind in cind, aleator, imi apare bitul INT0IF = 1. void TC74(void){IdleI2C();cmnd = RTR; //debug line!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// 1. StartStartI2C(); while ( SSPCON2bits.SEN ); // wait until start condition is over IdleI2C();// 2. Send slave address & Write command (about to write address)WriteI2C(TC74ADDW); IdleI2C(); // Check ACK/NACK while (SSPCON2bits.ACKSTAT); //Bit 6 // 3. Write command WriteI2C(cmnd); IdleI2C(); // Check ACK/NACK while (SSPCON2bits.ACKSTAT); // 4. Restart NB DIFFERENT FROM DATA SHEETRestartI2C(); while ( SSPCON2bits.RSEN ); // wait until re-start condition is over IdleI2C();// 5. Send slave address & Read commandWriteI2C(TC74ADDR); IdleI2C(); // Check ACK/NACK while (SSPCON2bits.ACKSTAT); // 6. Receive DataTC74Data = getcI2C(); IdleI2C();// 7. Generate NACKNotAckI2C(); IdleI2C();// 8. StopStopI2C(); IdleI2C();return;} Link spre comentariu
vlad_2770 Postat Decembrie 21, 2009 Autor Partajează Postat Decembrie 21, 2009 Cind rulez in debug programul vad ca nu pot sa fac: SEN: Start Condition Enabled/Stretch Enabled bit(1) = 1; adica instructiunea : SSPCON2bits.SEN = 1; nu are nici un efect. Mai jos in PDF scrie: For bits ACKEN, RCEN, PEN, RSEN, SEN: If the I2C module is not in the Idle mode, these bits may not be set (no spooling) and the SSPBUF may not be written (or writes to the SSPBUF are disabled). Cred ca imi scapa o setare pentru portul B de la care folosesc RB0 si RB1. Desi am configurat RB0 si RB1 ca intrari nu merge. Link spre comentariu
vlad_2770 Postat Decembrie 22, 2009 Autor Partajează Postat Decembrie 22, 2009 In continuare ma izbesc de problema asta: If at the beginning of the Start condition, the SDA and SCL pins are already sampledlow, or if during the Start condition, the SCL line is sampled low before the SDA line is driven low, a bus collision occurs,the Bus Collision Interrupt Flag, BCLIF, is set, the Start condition is aborted and the I2C module is reset into its Idle state.Desi am rezistente de pull-up de 4,7k cind doresc sa fac SEN = 1 imi apare bus collision si gasesc bitul BCLIF in 1 logic. Am scos senzorul si am lasat in aer RB0 si RB1 si tot asa imi face. Care sa fie oare greseala?Multumesc Link spre comentariu
Liviu M Postat Decembrie 22, 2009 Partajează Postat Decembrie 22, 2009 Eu banuiesc o problema de initializare (la PIC-uri). Vezi (in Data Sheet-uri) ce difera la initializarile controllerelor.Sau posteaza si codul de initializare, poate se prinde cineva. Link spre comentariu
vlad_2770 Postat Decembrie 22, 2009 Autor Partajează Postat Decembrie 22, 2009 pt 18F452:#pragma config OSC = HS //LT/HS/RC/EC/ECIO/HSPLL/RCIO /Oscillator type/#pragma config OSCS = OFF //ON /Oscillator switch/#pragma config PWRT = OFF //ON /Power-up timer/#pragma config BOR = ON //OFF* /Brown out reset/#pragma config BORV = 25 //4227/45 /Brown out voltage/#pragma config WDT = OFF //ON /Watchdog timer/#pragma config WDTPS = 128 // /Watchdog postscaler/#pragma config CCP2MUX = OFF //(=RB3) /ON /CCP2MUX#pragma config STVR = ON //OFF /Stackoverflow reset/#pragma config LVP = OFF //ON /Low voltage progrommingADCON1 = 0x00 ; TRISA = 0xff ; TRISD = 0b00001111;TRISC = 0b00011000; // Setup PORTC for I2C lines (SDA & SCL)SSPADD= 0x63;si pentru 18F2455:#pragma config PLLDIV = 5 // (20 MHz crystal on PICDEM FS USB board) #pragma config CPUDIV = OSC1_PLL2 #pragma config USBDIV = 2 // Clock source from 96MHz PLL/2 #pragma config FOSC = HSPLL_HS #pragma config FCMEN = OFF #pragma config IESO = OFF #pragma config PWRT = OFF #pragma config BOR = ON #pragma config BORV = 3 #pragma config VREGEN = ON //USB Voltage Regulator #pragma config WDT = OFF #pragma config WDTPS = 32768 #pragma config MCLRE = ON #pragma config LPT1OSC = OFF #pragma config PBADEN = OFF #pragma config STVREN = ON #pragma config LVP = OFF #pragma config XINST = OFF // Extended Instruction Set #pragma config CP0 = OFF #pragma config CP1 = OFF #pragma config CPB = OFF #pragma config WRT0 = OFF #pragma config WRT1 = OFF #pragma config WRTB = OFF // Boot Block Write Protection #pragma config WRTC = OFF #pragma config EBTR0 = OFF #pragma config EBTR1 = OFF #pragma config EBTRB = OFF ADCON1 = 0x00 ; TRISA = 0xff ; TRISB = 0b00000011; PIE1 |= 0b00001000; PIE2 |= 0b00001000; SSPADD= 0x63; // Assuming 40MHz speed - 100KHz PIR2bits.BCLIF = 0; PIE1bits.SSPIE = 0; Link spre comentariu
Liviu M Postat Decembrie 23, 2009 Partajează Postat Decembrie 23, 2009 1. Nu se vede configuratia pentru SSPCON1.2. Cu SSPADD=0x63 mie imi da un clock de 50 kHz; nu cred ca-i o problema, da' poti incerca sa-l faci 100 kHz.Cu exceptia observatiei de mai sus (2), eu nu vad nimic ciudat. Tinand cont ca a functionat la 452... Link spre comentariu
vlad_2770 Postat Decembrie 23, 2009 Autor Partajează Postat Decembrie 23, 2009 de SSPCON1 are grija functia:void OpenI2C( unsigned char sync_mode, unsigned char slew ){ SSPSTAT &= 0x3F; // power on state SSPCON1 = 0x00; // power on state SSPCON2 = 0x00; // power on state SSPCON1 |= sync_mode; // select serial mode SSPSTAT |= slew; // slew rate on/off I2C_SCL = 1; I2C_SDA = 1; SSPCON1 |= SSPENB; // enable synchronous serial port }am incercat si cu 100KHz si cu 50KHz dar nici o schimbare. Singura problema ramane de la configurarea lui 18F2455 sau 18F2550. Am incercat cu ambele si comportamentul fiind identic nu-mi ramane decit sa trag concluzia ca este de la configurare, codul fiind identic intre 18F452 si 18F2455 (ca asta este acum pe placa). Dar probabil ca din cauza ca sunt ofuscat nu vad unde este hiba la configurare. Link spre comentariu
Liviu M Postat Decembrie 23, 2009 Partajează Postat Decembrie 23, 2009 In tabelul de la pagina 117 (in data sheet) iti arata valorile bitilor tris pentrudiversele configuratii ale pinilor portului B.La SDA TRIS e tot timpul 1 (intrare), da' la SCL e 1 sau 0 in functie de... functie.Incearca si cu SCL iesire (tu il faci la inceput intrare). Link spre comentariu
vlad_2770 Postat Decembrie 23, 2009 Autor Partajează Postat Decembrie 23, 2009 Ca de obicei, la nervi am tot schimbat configurarile si pina la urma in varianta finala a ramas ADCON1 = 0x00 in loc de ADCON1 = 0x0F ; Nu mai stiu ce cod am luat de pe net si mi-a ramas 0x00 in loc de 0x0F. In varianta initiala foloseam codul din proiectul CDC si acolo am si acum : static void InitializeSystem(void) { //On the PIC18F87J50 Family of USB microcontrollers, the PLL will not power up and be enabled //by default, even if a PLL enabled oscillator configuration is selected (such as HS+PLL). //This allows the device to power up at a lower initial operating frequency, which can be //advantageous when powered from a source which is not gauranteed to be adequate for 48MHz //operation. On these devices, user firmware needs to manually set the OSCTUNE bit to //power up the PLL. #if defined(__18F87J50)||defined(__18F86J55)|| \ defined(__18F86J50)||defined(__18F85J50)|| \ defined(__18F67J50)||defined(__18F66J55)|| \ defined(__18F66J50)||defined(__18F65J50) unsigned int pll_startup_counter = 600; OSCTUNEbits.PLLEN = 1; //Enable the PLL and wait 2+ms until the PLL locks before enabling USB module while(pll_startup_counter--); //Device switches over automatically to PLL output after PLL is locked and ready. //Configure all I/O pins to use digital input buffers. The PIC18F87J50 Family devices //use the ANCONx registers to control this, which is different from other devices which //use the ADCON1 register for this purpose. WDTCONbits.ADSHR = 1; // Select alternate SFR location to access ANCONx registers ANCON0 = 0xFF; // Default all pins to digital ANCON1 = 0xFF; // Default all pins to digital WDTCONbits.ADSHR = 0; // Select normal SFR locations #elif defined(PIC18F2455_PICDEM_FS_USB) ADCON1 |= 0x0F; // Default all pins to digital #else #error Double Click this message. Please make sure the InitializeSystem() function correctly configures your hardware platform. //Also make sure the correct board is selected in usbcfg.h. If //everything is correct, comment out the above "#error ..." line //to suppress the error message. #endif // The USB specifications require that USB peripheral devices must never source // current onto the Vbus pin. Additionally, USB peripherals should not source // current on D+ or D- when the host/hub is not actively powering the Vbus line. // When designing a self powered (as opposed to bus powered) USB peripheral // device, the firmware should make sure not to turn on the USB module and D+ // or D- pull up resistor unless Vbus is actively powered. Therefore, the // firmware needs some means to detect when Vbus is being powered by the host. // A 5V tolerant I/O pin can be connected to Vbus (through a resistor), and // can be used to detect when Vbus is high (host actively powering), or low // (host is shut down or otherwise not supplying power). The USB firmware // can then periodically poll this I/O pin to know when it is okay to turn on // the USB module/D+/D- pull up resistor. When designing a purely bus powered // peripheral device, it is not possible to source current on D+ or D- when the // host is not actively providing power on Vbus. Therefore, implementing this // bus sense feature is optional. This firmware can be made to use this bus // sense feature by making sure "USE_USB_BUS_SENSE_IO" has been defined in the // usbcfg.h file. #if defined(USE_USB_BUS_SENSE_IO) tris_usb_bus_sense = INPUT_PIN; // See io_cfg.h #endif // If the host PC sends a GetStatus (device) request, the firmware must respond // and let the host know if the USB peripheral device is currently bus powered // or self powered. See chapter 9 in the official USB specifications for details // regarding this request. If the peripheral device is capable of being both // self and bus powered, it should not return a hard coded value for this request. // Instead, firmware should check if it is currently self or bus powered, and // respond accordingly. If the hardware has been configured like demonstrated // on the PICDEM FS USB Demo Board, an I/O pin can be polled to determine the // currently selected power source. On the PICDEM FS USB Demo Board, "RA2" // is used for this purpose. If using this feature, make sure "USE_SELF_POWER_SENSE_IO" // has been defined in usbcfg.h, and that an appropriate I/O pin has been mapped // to it in io_cfg.h. #if defined(USE_SELF_POWER_SENSE_IO) tris_self_power = INPUT_PIN; #endif mInitializeUSBDriver(); // See usbdrv.h UserInit(); // See user.c & .h }//end InitializeSystem Normal ca stiind o fata facut ADCON1 = 0x0F am ramas cu impresia ca totul este ok. Multumesc mult de ajutor celor care mi-au scris aici si pe mp. Daca nu deschideam acest topic nu as fi rezolvat problema si m-as fi invartit mult si bine in jurul cozii. Link spre comentariu
vlad_2770 Postat Decembrie 23, 2009 Autor Partajează Postat Decembrie 23, 2009 revin cu o precizare, nu era problema de ADCON1, ci faptul ca trebuie configurat pull-up-urile pentru portul B . Am fost "furat" de acea configurare, dar nu era din proiectul curent. Deci ce lipsea ere: INTCON2bits.RBPU=0; Am testat si asta era hiba. Link spre comentariu
Postări Recomandate
Creează un cont sau autentifică-te pentru a adăuga comentariu
Trebuie să fi un membru pentru a putea lăsa un comentariu.
Creează un cont
Înregistrează-te pentru un nou cont în comunitatea nostră. Este simplu!
Înregistrează un nou contAutentificare
Ai deja un cont? Autentifică-te aici.
Autentifică-te acum