i2c / 2wire usage

Questions for programming 8051 microcontrollers in C or assembly using SDCC

i2c / 2wire usage

Postby baruch » Fri Jan 23, 2015 3:23 pm

I'm trying to communicate with an i2c temperature sensor but so far didn't manage to get i2c communicating at all, I'm using a logic analyzer to see the communication and there is just no change. I use the nRF24LE1 32 pin unit so I expect the bit twiddling on P0.4 and P0.5 but there is absolutely nothing on it. P0.5 is always low and P0.4 is always high.

The code I use is:

Code: Select all
void main()
{
   uint8_t req = 0xE3;
   uint16_t data = 0xBEBE;

   pwr_clk_mgmt_cclk_configure(PWR_CLK_MGMT_CCLK_CONFIG_OPTION_CLK_FREQ_16_MHZ);
   delay_s(1);

   w2_configure(W2_CONFIG_OPTION_CLOCK_FREQ_100_KHZ | W2_CONFIG_OPTION_MODE_MASTER | W2_CONFIG_OPTION_ENABLE, 0);
   w2_enable();
   interrupt_control_global_disable();
   delay_s(1);

   while(1)
   {
      w2_ack_nack_val_t ret;
      ret = w2_master_random_address_read(0x40, &req, sizeof(req), (uint8_t*)&data, sizeof(data));
      delay_s(1);
   }
}


Anyone has an idea? Code sample that worked?
baruch
 
Posts: 14
Joined: Mon Nov 17, 2014 10:15 am

Re: i2c / 2wire usage

Postby brennen » Sat Jan 24, 2015 11:54 pm

Here's a link to some code I used to get I2C working with an I2C EEPROM: http://www.diyembedded.com/examples/nrf ... eeprom.zip
brennen
Site Admin
 
Posts: 395
Joined: Sun Aug 17, 2008 2:15 pm

Re: i2c / 2wire usage

Postby baruch » Tue Jan 27, 2015 5:26 pm

I've tried loading the ihx in the zip and I can't see it doing anything. Now I'm starting to wonder if I have a hardware problem somewhere, either my soldering or the board itself. I tested continuity and everything works and there doesn't seem to be any short.

I don't have the EEPROM device you were using by I expected to at least see the clock signal goes up and down and some data transmitted even if the transaction is not completed fully. But there is just a straight line on the logic analyzer.
baruch
 
Posts: 14
Joined: Mon Nov 17, 2014 10:15 am

Re: i2c / 2wire usage

Postby brennen » Tue Jan 27, 2015 8:49 pm

Two things:

1) Do you have pull-up resistors installed on the SDA and SCL lines?
2) Do you see serial output from the example program (just to make sure code is, in fact, running)?
brennen
Site Admin
 
Posts: 395
Joined: Sun Aug 17, 2008 2:15 pm

Re: i2c / 2wire usage

Postby baruch » Tue Jan 27, 2015 9:42 pm

1) The i2c devices I have are on a breakout board and they have resistors on the SDA/SCL lines for all I can see.
2) I do not have a wire soldered on the TX line but when I touched it with a wire I did see signals though I failed to dechipher them as serial at 38400 as I expected to see.

I did another try and removed the board I use from the programmer socket (I program through an Arduino) and now I can see the clock signal going on but the data line doesn't toggle. I suspect I have my wiring wrong now and that the i2c is indeed functioning, probably something on the programmer confused things up. Still not working but at least I have some progress in the debug.
baruch
 
Posts: 14
Joined: Mon Nov 17, 2014 10:15 am

Re: i2c / 2wire usage

Postby baruch » Wed Jan 28, 2015 6:18 am

After the last change I switched pins on the logic analyzer and now it shows the transaction, looks like the i2c device simply nacks all my commands. At least now I know the nrf unit actually does the right thing and transmits, now I'll figure the i2c issue itself.

To sum it up, the nrf was on the programmer which interfered with the i2c bus, removing it from the programmer made it work and the logic analyzer was lying to me on one of its pins.
baruch
 
Posts: 14
Joined: Mon Nov 17, 2014 10:15 am

Re: i2c / 2wire usage

Postby brennen » Wed Jan 28, 2015 1:35 pm

I'm not sure if you wrote the programming code on your Arduino, but I would *highly* suggest tri-stating all of the programming pins when the programmer is not active (i.e., making them inputs). You can also put series 1k resistors on the programming lines between the Arduino and the LE1 for added protection. If you do this, then the programmer shouldn't interfere with your I2C bus at all.
brennen
Site Admin
 
Posts: 395
Joined: Sun Aug 17, 2008 2:15 pm

Re: i2c / 2wire usage

Postby baruch » Wed Jan 28, 2015 3:08 pm

I didn't write the arduino programmer myself but I adapted it enough to feel free to do some more. I'll check out that tri-stating suggestion. It would make life easier without needing to remove the module from the programmer in development.

Thanks!
baruch
 
Posts: 14
Joined: Mon Nov 17, 2014 10:15 am

Re: i2c / 2wire usage

Postby baruch » Wed Jan 28, 2015 8:37 pm

I set the pins to tri-state and now it all works out! Thanks for the suggestion!

The code for those who care lives at https://github.com/baruch/nRF24LE1_Programmer
This is a modified fork of https://github.com/DeanCording/nRF24LE1_Programmer
baruch
 
Posts: 14
Joined: Mon Nov 17, 2014 10:15 am

Re: i2c / 2wire usage

Postby 07albi » Thu May 21, 2015 7:56 am

Hello,
sorry to revive this topic, but I have similar problem to this. I am trying to get the I2C working. I have the nerf24le1 connected to board with two I2C sensors. The SDA and SCL are pull-uped with 10k resistors.

I tried to use your I2C example, but with logic analyzer, there was no change at all on neither SDA or SCL. I am using your arduino programmer, but I always disconnect it from the board before testing, so there should not be any interference. I was able to test the board with arduino 2wire library, and it is working fine(I can communicate with the sensors on the board).

I also fount out, that if I tried to use, for example, this function w2_master_write_control_bytes.c, the MCU will halt( I had a led blink function at the end of code). So I tried just to configure the 2wire protocol as master and used the w2_send_start_condition(), but again no change on SDA, but the blink did work.

Am I missing something here? Also tried to flash these pre-compiled examples(https://devzone.nordicsemi.com/question ... g-problem/), but no change again.

Thank you for any ideas.
07albi
 
Posts: 4
Joined: Thu May 21, 2015 7:45 am

Next

Return to 8051 Programming

Who is online

Users browsing this forum: No registered users and 2 guests

cron