|
|
View previous topic :: View next topic |
Author |
Message |
BrianC
Joined: 23 Apr 2022 Posts: 11 Location: UK
|
18F26K42 I2C |
Posted: Sun Apr 24, 2022 12:16 pm |
|
|
I missed the word 'nothing' out of the previous message.
Point taken, but the reality is there is nothing showing up on the i2c protocol analyser, not even a 'start' transition, so I doubt it is getting that far. When you run the code under debug it stops in a tight loop within the code for the #use statement. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Apr 24, 2022 1:27 pm |
|
|
The reason it stops is because you are filling in the parameters
for i2c_transfer() incorrectly. Ttelmah told you to look at how he
passes two bytes of data to the function. Here is his example:
Code: |
void write_ext_eeprom(BYTE address, BYTE data) {
int [b]to_send[2];[/b]
while(!ext_eeprom_ready())
;
to_send[0]=address;
to_send[1]=data; //setup data to send
i2c_transfer(I2C, EEPROM_R, to_send, 2);
}
|
Note that he doesn't create two variables called 'i2c_control' and
'i2c_data' as you have done. He creates an array. Then he
puts the two bytes he wants to send into the array. Then he
gives the address of the array to i2c_transfer() as the 3rd parameter.
I have labeled his parameters below:
Code: |
i2c_transfer(I2C, EEPROM_R, to_send, 2);
// stream i2c addr, pointer # data bytes
// to data in the array
// array
|
Let's look at what you're doing:
Code: |
i2c_transfer(I2C, i2c_lcd_address, i2c_control, i2c_data, 3 );
// stream, i2c address , ptr_wrt_data, wrt_count, extra
// 0x7C *** wrong *** 0
|
1. The parameter after the i2c address is supposed to be a pointer
to the data array. But you're giving it the value of i2c_control.
That's not going to work.
2. Next, for the write count, you're giving it the value of i2c_data,
but that's set to 0 in your previous code. So you're telling it to send 0 bytes.
3. Finally, you have the extra parameter of '3'. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19589
|
|
Posted: Sun Apr 24, 2022 10:55 pm |
|
|
Thanks PCM.
I actually wondered if the extra parameter, might make the code 'switch' to
the overloaded version that tries to perform a read. Wasn't sure.
The key point is that the function is being called incorrectly. Not surprising
it doesn't work... |
|
|
BrianC
Joined: 23 Apr 2022 Posts: 11 Location: UK
|
18F26K42 I2C |
Posted: Mon Apr 25, 2022 5:20 am |
|
|
Many thanks for the help on this.
Before I go totally out of my mind, have I now got this correct? as it still fails at the same point, I can track it all the way through loading the array to it doing the 'i2c_transfer' of the data from the array, then it sits there in the #use i2c waiting for x73.5 to be cleared (though don't know what that refers to ?? ). So it is still doing the same thing as previous. I have tried all sorts of parameters in the use i2c but to no effect. I have also tried using transfer_out but same result.
Code: |
//check if LCD is ready
Boolean ext_lcd_ready()
{int1 ack;
ack=i2c_transfer(I2C,i2c_lcd_address,NULL,0);
return !ack;
}
//==========================================================================
void WRITE_CODE(int8 i2c_control,int8 i2c_data)
{
int8 To_Send[2];
while (!ext_lcd_ready());
To_Send[0]=i2c_control;
To_Send[1]=i2c_data;
i2c_transfer(I2C,i2c_lcd_address,To_Send,2);
}
//====================================================================
static void Initial_st7032()
{
WRITE_CODE(0x00,0x38);
delay_us(300);
WRITE_CODE(0x00,0x38);
delay_us(300); |
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19589
|
|
Posted: Mon Apr 25, 2022 5:48 am |
|
|
What voltage are you running the chip?.
What voltage is the device attached?.
What voltage are the pull-ups connected to?.
The bit is the bit to start the I2C transaction. To actually send the start.
The data sheet says it will clear automatically. However it also says it
will test that the bus is 'idle' before it'll work. Idle on I2C, is both lines
being seen as 'high'. So the only reason it'd hang here is if the lines are
not being seen as high. Now not being 'seen', would apply if the lines
are not getting up to at least 0.8* the supply voltage. Or of the wrong
pins were being setup in the PIN_SELECT (so you were actually pulling
up a different pin).
You talk about the LCD. Forget this. Just do a basic test to set something
in the chip involved. KISS. |
|
|
BrianC
Joined: 23 Apr 2022 Posts: 11 Location: UK
|
18F26K42 I2C |
Posted: Mon Apr 25, 2022 6:24 am |
|
|
A very big thankyou ! I found a supply issue on the track going to the pull-ups. |
|
|
|
|
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
|