I have found on the internet a code to reading the obd KKL kw1281 protocol.(I have attach the code)
The code it works very good with software serial with baudrate 10400.
My main problem is that when i add i2c requestEvent fuction with wire.write() the software serial lost same data when it come a request event from i2c.
To solve this problem i decide to make the serial communication with hardware serial.
My problem is that the hardware serial it dosent work at this baud rate.At the start of the code it receiving the first 3 bytes 0x55, 0x01, 0x8A but after that it dosent work.
My problem is that the hardware serial it dosent work at this baud rate.At the start of the code it receiving the first 3 bytes 0x55, 0x01, 0x8A but after that it dosent work.
has anyone any idea what i must to do ?
Attach the code that doesn't work. Looking at the code that does work isn't going to help.
Sure. Just work the equations the opposite direction, to determine what the crystal frequency needs to be to get an acceptable error rate. Then buy a crystal of that frequency and solder it in place of the existing one.
Be sure to change EVERYTHING else that the Arduino does that depends on clock frequency.
The hard question is that you may come up with a calculation that might suggest a very odd-valued (frequency) crystal which mat not be available in the market. So, you have to make a sound judgement depending on these parameters.
Know the frame length of your async telemetry : START Bit (1) + Data Bit (7 or 8), Parity Bit (0 or 1) + STOP Bit (1 or 2). It is needed; because, the %error varies with these parameters. Let us assume frame length = 10. Acceptable error in Bd is: +/- 2% (10192 <--10400--> 10608).
===> Bd = 8*106/16(UBBR+1)
===> Bd = 10416 (allowable range: 10192 to 10608 to comply with +/- 2% error for Bd = 10400)
If you are using Arduino UNO, there is no need to change the crystal; leave it as it is at 16 MHz. Change the CLKPR (Clock Prescaler) setting (Fig-1) to obtain an operating frequency of 8 MHz.
Figure-1: CLKPR Register of Arduino UNO/NANO/MEAGA
Now the question is -- will this Serial.begin(10400) instruction work? Probably, it will work with another Arduino; but, it will not work with the Serial Monitor as there is no option to set the Bd of the Serial Monitor at 10400 Bd. The available Bds for the Serial Monitor of IDE-1.8.5 are: 300, 1200, 2400, 4800, 9600, 19200, 38400, 57600, 74880, ..., 2000000.
and the i2c will work correct if i change the prescale?
We are talking about UART Port. Correct? Why is I2C here?
The codes that you have posted is copied and pasted or you have prepared it?
You should try to write your own codes to operate the UART Port at 10400 Bd.
1. Initialize the UART Ports of UNO-1/UNO-2 for using register level instructions for the following parameters: Bd 10400, Data Bits 8, No parity, Stop Bit 1. Load 0x00 into UBRRH Register and 47 into UBRRL Register.
2. Use register level instructions to set CKPR Register at division factor 2 for UNO-1/UNO-2.
3. Connect a LCD with UNO-2 to monitor message to be arrived from UNO-1 at Bd 10400. You have no opportunity to use Serial Monitor neither for UNO-1 nor for UNO-2.
4. Send the following message to UNO-2. char s[5] = {'F', 'i', 'n', 'e', '\0'}; via UART Port of UNO-1 by executing the instruction: Serial.print(s);.
I found the setClockPrescaler fuction and i write the code to test it.but i write baud rate 115200 and this actually is 57600 thats why i shay that maybe i must set the double baud rate.
In this code if i set UBRRH=0 and UBRRL=47 it will works with serial monitors?
I am trying to test it with serial monitor to see the actually baud rate.
Because if i test it with two arduinos with CKPR =2 will work but maybe both run on work baud rate correct?
I told for i2c because in the future i want to add some i2c request.