CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Two Non-Standard SPI Devices on Same SPI Bus

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
jecottrell



Joined: 16 Jan 2005
Posts: 559
Location: Tucson, AZ

View user's profile Send private message

Two Non-Standard SPI Devices on Same SPI Bus
PostPosted: Sat Mar 03, 2007 9:21 pm     Reply with quote

Hello All,

I've got a TC77 that I'm using the following code to drive:

Code:
unsigned int16 read_tc77(void)
{
   unsigned int16 data = 0;
   unsigned int16 F    = 0;
   int8 i;

   delay_ms(100);

   output_high(TC77_CS); //select the TC77
   delay_ms(10);
   output_low(TC77_CS); //select the TC77

   for(i = 13; i > 0; i--)
   {
      output_high(PIN_C3); //clock
      delay_us(10);
      output_low(PIN_C3);
      delay_us(10);
      if (input(PIN_C5))
         bit_set(data,i);
   }
   output_high(TC77_CS); //deselect the TC77

   data >>= 6; //to get rid of the fraction of a degree

   F = (unsigned int16) ((1.8 * data) + 32);

}


I'm also using a Toshiba TB62726 LED Driver. The TC77 and the TB62726 share the same data and clock pins. It appears that neither have a 'true' chip-select. So when I read the TC77 the TB62726 'accepts' the data for the TC77 even when the TB62726 LATCH pin is held high during the transaction meant for the TC77. I think my largest problem is understanding the finer points of the term 'leveled latch circuit' as described in the TB62726 datasheet. Is there some way for me to get these two devices to co-exist on the same bus? I've tried resending the data to the TB62726s (30 of them daisy chained) after a TC77 read, but the time it takes to read the TC77 and resend the data is too long. It causes the LEDs to flash.

Also, I had to bit bang the SPI for the TB62726.

Can anyone offer any suggestions?

Thanks,

John

TB62726 Data Sheet:

http://www.marktechopto.com/pdfs/Toshiba/TB62726ANG_AFG.pdf (pg. 3)
cmdrdan



Joined: 08 Apr 2005
Posts: 25
Location: Washington

View user's profile Send private message

Toshiba TB62726
PostPosted: Sun Mar 04, 2007 1:30 am     Reply with quote

Hello John --

First let me say that I've never used either of the devices you mentioned, but looking at the Toshiba datasheet you referenced indicates that you want to keep the LATCH pins low until you've written all 16 * 30 bits, then pulse the LATCH pins high for at least 50 nanoseconds, then bring them low again.

The 'leveled latch circuit' means that the outputs will 'follow' whatever you're clocking through the device as long as the LATCH pin is high, so that is why you need to keep it low, and only bring it high and then low once you've clocked all of your data through. This should keep your LEDs from flashing in the meantime...

Refer to page 2 block diagram, and see that the ST inputs to the latches don't have a caret (>) next to them, while the CK inputs do -- the caret means that the input is edge-sensitive instead of level-sensitive.

Hope this helps you; I haven't looked at the TC77 datasheet to see how they might interact.

Dan
Kenny



Joined: 07 Sep 2003
Posts: 173
Location: Australia

View user's profile Send private message

PostPosted: Sun Mar 04, 2007 1:55 am     Reply with quote

It looks to me that the TC77 does have a true chip select and that
the TD62726 does not. It means that as you say, the data to or from
the TC77 will be clocked into the registers of the TD62726 regardless
of the state of LATCH. This shouldn't matter, the state of the leds won't
change until LATCH is brought high then low after a write, and the
registers will be 'flushed' next time data is written.

I think that 'leveled latch circuit' means that LATCH is
level-triggered instead of edge-triggered; the document has many
such translation problems.

If speed is required so that other processes can be serviced, a pic with
the SPI hardware could be used.


Last edited by Kenny on Sun Mar 11, 2007 4:11 pm; edited 1 time in total
jecottrell



Joined: 16 Jan 2005
Posts: 559
Location: Tucson, AZ

View user's profile Send private message

PostPosted: Sun Mar 04, 2007 8:50 am     Reply with quote

Thanks Guys,

That was exactly what I needed. I ended up with some bunged up code after a bunch of debugging. I took your suggestions and followed the Toshiba datasheet and it works fine.

I ended up having to bit-bang the Toshiba part because after I setup_spi for the Toshiba the TC77 quits working. I assume that has something to do with the way the pins are configured when you call setup_spi? Is there a way I can 'un-do' the setup_spi call when I need to read the TC77? I would guess I just need to set the pins that the TC77 uses to the proper directions... no? Or is there a simple, one-step solution?

Thanks again,

John
Kenny



Joined: 07 Sep 2003
Posts: 173
Location: Australia

View user's profile Send private message

PostPosted: Sun Mar 04, 2007 11:19 am     Reply with quote

What SPI mode did you use? Mode 0 should work for both. The data
sheet for the TB62726 shows that the clock should be normally low
and data is sampled on the rising edge of the clock.
It looks like either Mode 0 or Mode 3 might work for the TC77.

If it turns out that they need separate spi modes, you could try setting
the mode in the code for each just before using it.

I like to use ckielstra's handy SPI definitions:
#define SPI_MODE_0_0 (SPI_L_TO_H | SPI_XMIT_L_TO_H)
#define SPI_MODE_0_1 (SPI_L_TO_H)
#define SPI_MODE_1_0 (SPI_H_TO_L)
#define SPI_MODE_1_1 (SPI_H_TO_L | SPI_XMIT_L_TO_H)


eg. for the TC77
setup_spi(SPI_MASTER | SPI_MODE_1_1 | SPI_CLK_DIV_4);

Read the two temperature bytes, then deselect it.
Note: can't write to TC77 with hardware spi; pic SDI pin is
for input only. If required to write the config. , would need to do this
in bit banging mode.

setup_spi(SPI_MASTER | SPI_MODE_0_0 | SPI_CLK_DIV_4);

Send the data to the TB62726


Last edited by Kenny on Wed Mar 07, 2007 4:05 pm; edited 2 times in total
jecottrell



Joined: 16 Jan 2005
Posts: 559
Location: Tucson, AZ

View user's profile Send private message

PostPosted: Sun Mar 04, 2007 11:27 am     Reply with quote

Kenny,

No, I think the problem was caused by me when I layed out the board and didn't fully understand the TC77. I fed the TC77 data pin to the MOSI on the PIC hardware SPI. So I'm forced to bit bang the TC77. It's the swap from TC77 to Toshiba, hardware to software SPI that causes problems. I think, like I said, the issue is probably with swapping the MOSI pin from output to input to read the TC77?

I'd like to learn more about what setup_spi does. I haven't looked at the LST file... not that I'd know what I was looking at. But that would probably tell me more?

Thanks,

John
Kenny



Joined: 07 Sep 2003
Posts: 173
Location: Australia

View user's profile Send private message

PostPosted: Sun Mar 04, 2007 12:25 pm     Reply with quote

Oh dear, that complicates matters. I think you need to disable the
hardware spi before doing the bit banging for the TC77.
Either setup_spi(FALSE), or clear the SSPEN bit in SSPCON.

Re understanding setup_spi, I agree that it's difficult sometimes to
get an understanding just by looking at the list file. The hardware
description in the data sheet is the key to understanding.
The spi hardware is described in the Synchronous Serial Port (MSSP) module section.

HTH
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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