|
|
View previous topic :: View next topic |
Author |
Message |
camleot23
Joined: 16 Aug 2019 Posts: 52
|
[SOLVED]dsPIC33F #fuses config set for clock and I2C |
Posted: Fri Aug 16, 2019 1:59 am |
|
|
Hello All,
I'm using dsPIC33FJ32GP204. I'm kind of newbie and sorry for the easy mistakes first of all. I'm trying to do my research.
I wrote a code that works well for PIC16F877 using i2c that communicates with eeproms and lcd. But when I copy paste it to the dsPIC33f (changing with device id) when i use simulator and when I set the dsPIC clock property to 20Mhz same with the delay in code, that known simulator gives me "Start hold time violated. (I don't care about the simulator, I just want to learn that my configs are set correctly) Start was at bla bla bla" Stop setup time violated. Last change on SDA was at bla bla bla".
In short, when I set both delay and mcu's clock setting the same not in just 20Mhz case, I get the error. I kind of solved this issue setting mcu's clock freq. to 8Mhz while delay is 20Mhz in code but I don't accept this as a solution. Please help me. And I really don't know whether my clock config or simulator is the problem. That's make me crazy. (I don't care about the simulator, I just want to learn that my configs are set correctly. Just think about my fuse settings.)
I want to use a crystal. And I want system clock speed to be 20Mhz.
My #fuses are like this:(I just have these settings as a clock setup)
Code: |
#include <./33FJ32GP204.h>
#include <stdlib.h>
#fuses HS,PR
#fuses NOALTI2C1
#fuses NODEBUG,NOPUT,NOPROTECT,NOWRT,NOWDT
#use delay(crystal=20000000)
|
MPLAB X IDE v5.2
CCS C Compiler as a plugin 3.1
Last edited by camleot23 on Wed Aug 21, 2019 7:19 am; edited 1 time in total |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19620
|
|
Posted: Sat Aug 17, 2019 12:40 am |
|
|
You are posting the wrong stuff.
You clock settings need to be right. The real chip won't change, you are
just 'tricking' the simulator into thinking the chip is running slower than
it actually is. This won't help for a real chip.
The parts that matter, are the I2C configuration, and your actual I2C code.
The commonest problem is just sending things too fast.
I've posted in the past, that on some fast chips you may have to add a
short delay after an I2C_Stop, before starting a new transaction. This is
simply because the instruction returns immediately, while the 'stop' is
still being generated, and on the faster DsPIC's, it is possible otherwise
to try to generate the next 'start' too soon. Similarly on a slow (100KHz)
peripheral, you may actually need to delay between the I2C_Start, and
sending the first byte. |
|
|
camleot23
Joined: 16 Aug 2019 Posts: 52
|
|
Posted: Sun Aug 18, 2019 11:57 pm |
|
|
Thank you for your response.
Here is my i2c functions;
Code: | #define hi(x) (*((int8 *)&x+1))
BOOLEAN eeprom_ready(long int device_adres) {
int1 ack;
i2c_start(); // If the write command is acknowledged,
ack = i2c_write(device_adres); // then the device is ready.
i2c_stop();
return !ack;
}
void eeprom_write(long int address,long int device_adres, BYTE data) {
while(!eeprom_ready(device_adres));
i2c_start();
i2c_write(cihaz_adres);
i2c_write(hi(address));
i2c_write(address);
i2c_write(data);
i2c_stop();
}
int eeprom_read(long int address, long int device_adres) {
int data;
while(!eeprom_ready(device_adres));
i2c_start();
i2c_write(device_adres);
i2c_write(hi(address));
i2c_write(address);
i2c_start();
i2c_write(device_adres+1);
data=i2c_read(,0);
i2c_stop();
return(data);
} | I'm looking forward to your response.
Last edited by camleot23 on Mon Aug 19, 2019 12:23 am; edited 1 time in total |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19620
|
|
Posted: Mon Aug 19, 2019 12:22 am |
|
|
Add a short delay (couple of uSec), after the I2C_start before you do the
I2C_write, and a similar one after the I2C_stop. How long will depend on
the I2C speed you are using (which you still don't show). |
|
|
camleot23
Joined: 16 Aug 2019 Posts: 52
|
|
Posted: Mon Aug 19, 2019 12:24 am |
|
|
Do you mean this?
#use i2c(master, sda=PIN_B9, scl=PIN_B8,FAST) |
|
|
camleot23
Joined: 16 Aug 2019 Posts: 52
|
|
Posted: Mon Aug 19, 2019 12:52 am |
|
|
I'm adding delays but, it seems it doesn't work. Also, I have a LCD with dsPIC using i2c communication, real hardware. And I have a LCD flex i2c library which I got it from this forum. I added delays delay_us(40); like this after starts and before stops.
Code: |
#include <./33EP64MC206.h>
#fuses FRC
#fuses NODEBUG,NOPROTECT,NOWRT,NOWDT
#use delay(clock=7.37MHz,internal)
//I added stream name to all starts writes and reads in the library. In case if I want to use another stream for I2C.
#use i2c(master, sda=PIN_C4, scl=PIN_C5,STREAM=lcd_kanal)
#include <./i2C_Flex_LCD_with_BIGNUMBERS.h>
int main()
{
setup_timer1(TMR_DISABLED); // T1 zamanlay?c?s? devre d???
setup_timer2(TMR_DISABLED); // T2 zamanlay?c?s? devre d???
setup_adc_ports(NO_ANALOGS); // ANALOG giri? yok
setup_adc(ADC_OFF); // ADC birimi devre d???*/
lcd_init();
lcd_gotoxy(1,1);
lcd_putc("1.EEPRM yazildi: ");
delay_ms(10);
lcd_gotoxy(1,2);
lcd_putc("2.EEPRM yazildi: ");
set_tris_b(0x00);
while(1)
{
lcd_gotoxy(1,1);
lcd_putc("deneme");
delay_ms(1000);
output_toggle(pin_b5);
}
} |
|
|
|
camleot23
Joined: 16 Aug 2019 Posts: 52
|
|
Posted: Mon Aug 19, 2019 1:53 am |
|
|
#use i2c(master, sda=PIN_C4, scl=PIN_C5,FAST)
when I change the sda scl part to like this
#use i2c(master, I2C1)
I get no error . But on the real hardware still i cannot read anything from LCD. It is empty. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9296 Location: Greensville,Ontario
|
|
Posted: Mon Aug 19, 2019 5:26 am |
|
|
I'd change 'FAST' to 'SLOW', in the use I2C options.
LCD device do not require very fast data transfers.
Have you tried PCM P 'I2C scanner' program ? It's in the code library and is the FIRST program I use to test every I2C device.
Also have you run a '1Hz LED' program and confirmed the PIC is running at the correct speed ? THis should be the 1st program you run, then the scanner pgm.
Jay |
|
|
camleot23
Joined: 16 Aug 2019 Posts: 52
|
|
Posted: Mon Aug 19, 2019 5:44 am |
|
|
Thank you for your response temtronic.
I've heard PCP P for the first time and I don't know how to open it and where it is. I searched "PCP P " on the internet but I couldn't find anything.
Yes I run a led with 1Hz on my real circuit. It is toggeling in every second. I'm trying to use an internal oscillaor on that and also I opened another topic for this if you know how to set internal oscillator for dsPIC please read it and share your knowledge.
Thanks a lot.
EDIT: You mean PCM Programmer by PCM P .D Sorry. I found it in the forum. But I guess that won't work for me becuase I can't connect it to a serial port. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19620
|
|
Posted: Mon Aug 19, 2019 9:44 am |
|
|
All I2C drivers like this, need to be told what I2C address the device is on.
This is dependant on _your_ hardware.
Honestly, attach a USB to 3.3v serial adapter to your board, and you
then have serial available to you. With this you can run the scanner
program, and it'll tell you what address your device is actually being found on.
Tell us more about the display. Make?. Board from somebody?. If so, there
should be some data.
There are over 100 different device addresses that could be being used.
Without data, or a tester, there is no way to get this working.
There is also a potential issue, that a lot of I2C kit is 5v. Are you sure the
unit you have is compatible with a 3.3v PIC?. |
|
|
camleot23
Joined: 16 Aug 2019 Posts: 52
|
|
Posted: Mon Aug 19, 2019 11:10 am |
|
|
I understand you Ttelmah and I read your response for the other topic that I asked a question about internal oscillator for dspic. Thank you for your help, I'm really appriciated.
First that is not a kit, this is just a 10cmx10 a pcb that designed for modbus but the manufacturer didn't filled the other parts, there are just a led, resistor, and voltage out/in pins. I'm giving its voltage with pickit3. 3.5 volt and I'm supplying lcd's vcc and grnd from another source.
You are being focused on the 16x2 lcd hd44780, I know its address, I executed a code with it using arduino, and it's working with the 0x3F address. So, if you say 7.37Mhz is a right set up for internal oscillator, then problem is not about the clock settings. Then the last thing that I should worry about the soldering that I get I2C clock and data for the lcd. Because that sda and scl pins are wired on the pcb for a little eeprom so, I soldered two jumpers on that pins. Clock and data may not being transmitted correctly I guess.. I will try to solder it again then
And If you have any other guess about the problem that why lcd is empty, please share with me.
(Address is correct
and clock settings are correct
LCD is working) |
|
|
camleot23
Joined: 16 Aug 2019 Posts: 52
|
|
|
|
|
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
|