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 support@ccsinfo.com

Driver for SAA1061 port expander (CBUS).

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



Joined: 29 Jan 2011
Posts: 34

View user's profile Send private message

Driver for SAA1061 port expander (CBUS).
PostPosted: Fri Aug 19, 2022 1:45 am     Reply with quote

Hi,
Can anyone help with how to drive this SAA1061 port expander chip (last post dated 19th August 2022).

https://www.eevblog.com/forum/microcontrollers/old-cbus-serial-protocol-specification-any-info-out-here/msg4352107/#msg4352107

I am assuming that the driver would be nearly the same as for the PCE2111 LCD driver? However, I do not know how the chip is addressed or how the direction of the chip is controlled through the data stream. The SAA1061 seems to use a -2 or -3 suffix to indicate the address that has been hardwired using pins A0 and A1 (pins 7 and 4 respectively). I will do further research on how a priority encoder works but if anyone can describe how it works in THIS context that would be great. I have included here the previous code very kindly provided for the PCE2111 by Ttelmah (and slightly modified by me as I experiment with the code)

Code:

/*
FILENAME:REVOX_B261_PCE2111_LCD_TEST1.C
REVISION:0.1
Date:05 August 2022
Author: Original Ttelmah CCS INFO FORUM 04th August 2022 with contributions by David J S Briscoe
Purpose: This program is to test the Mullard/Philips PCE2111 Duplex 64 segment LCD driver on a Revox B261 FM tuner.
Status: 10th August:All segments are lit (apart from STORE and ANT-Check LCD connections.
Pin diagram

;              Target Controller - PIC16F1847
;                                                                                                                                 
;   RS232-WHITE------RA2 |1      18| RA1-----------
;   -----------------RA3 |2      17| RA0-----------
;   -----------------RA4 |3      16| RA7-----------
;   -----------------RA5 |4      15| RA6-----------
;   GND--------------VSS |5      14| VDD-----------+5V
;   PCE2111 DLEN-----RB0 |6      13| RB7-----------
;   PCE2111 DATA-----RB1 |7      12| RB6-----------
;   PCE2111 CLB------RB2 |8      11| RB5-----------
;   -----------------RB3 |9      10| RB4-----------
;                           
;
NOTES:
*/


#include <16F1847.H>
#fuses INTRC_IO, NOWDT, NOBROWNOUT, PUT,NOPROTECT,MCLR,NOLVP
#use delay(clock=8000000)
#use RS232(baud=9600, xmit=PIN_A2,ERRORS)         //RS232 on Pin A2

// Define pins for CBUS
#define DLEN PIN_B0
#define DATA PIN_B1
#define CLB PIN_B2 //set to suit you

int32 low32 = 0xFFFFFFFF;  //ALL segments ON
int32 high32 = 0xFFFFFFFF; //
//int32 low32 = 0x00000000;  //ALL segments OFF.
//int32 high32 = 0x00000000; //.
//int32 low32 = 0xFFDFFFFF;  //STEREO (SEG 22)OFF (all others ON).
//int32 high32 = 0xFFFFFFFF; //
//int32 low32 = 0xFFFFFF7F;  //25 OFF (SEG 8) ALL others ON.
//int32 high32 = 0xFFFFFFFF; //.
//int32 low32 = 0xFFFFFF7F;  //25 OFF. POINT AND MHZ OFF
//int32 high32 = 0xFFFFFF7F; //
//int32 low32 = 0xFFFFFFFF;  //75 OFF.25 AND 50 ON. 50 AND 75 SEG 32.
//int32 high32 = 0x7FFFFFFF; //
//int32 low32 = 0x7FFFFFFF;  //50 OFF REST ON
//int32 high32 = 0xFFFFFFFF; //



void init(void)
{
    //call at start to ensure lines are low
    output_low(DLEN);
    output_low(CLB);
}

#inline
void clock()
{
    //generate one bit clock
    delay_us(8);
    output_high(CLB);
    delay_us(2);
    output_low(CLB);
    delay_us(8);
}

void send(int32 value, int1 lowhigh)
{
    int ctr;
    int32 mask=1; //data is output LSb first
    output_high(DLEN);
    delay_us(8);
    //output 32bit value to either low or high register
    output_low(DATA);
    clock(); //first send a 0
    for (ctr=0;ctr<32;ctr++)
    {
        if (value & mask)
           output_high(DATA);
        else
           output_low(DATA);
        clock();
        mask*=2; //Modern compiler should optimise this to shift
    }
    if (lowhigh)
       output_high(DATA);
    else
       output_low(DATA);
    clock(); //clock out the bit to specify high/low register
    output_low(DLEN);
    clock(); //now clock this into the latches.
    delay_us(8); //do not do anything else for 8uSec
}

void main(void)
{
    int32 loop_cntr;
    for( loop_cntr = 0; loop_cntr < 0xffff; loop_cntr++)
    {
    init(); //ensure bus is initialised
    delay_us(100);
    //low32--;
    send(low32, 0); //load the low 32bits
    send(high32, 1); //load the high 32bits.
   //delay_us(100);
    //printf("Loop count: %8LX\r\n", loop_cntr);
   //printf("low32 value: %8LX\r\n", low32);
   delay_ms(1000);
   //printf("high32 value: %8LX\r\n", high32);
    printf("WORKING...\r\n");
    }
}



Maybe there are a few bits that need adding to the serial data stream, or maybe the DLEN line timing or operation needs to change. I'm not sure. I hope someone can help. Thank you.
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Sat Aug 20, 2022 1:13 am     Reply with quote

I posted a basic CBUS driver here:

[url]
https://www.ccsinfo.com/forum/viewtopic.php?t=59831
[/url]

Now the chip you are using uses 18 bits instead of the 32 bits here.
The 18 bits are the 16bits wanted for the 16 outputs, plus the A0 and
A1 bits (which you can set by wiring the two address pins).

Your device is a 5v unit against the 3v needed for the chip in the
post.
djsb



Joined: 29 Jan 2011
Posts: 34

View user's profile Send private message

PostPosted: Sat Aug 20, 2022 1:29 am     Reply with quote

Thanks Ttelmah,
As a start, maybe I should read the data sheet. I'm buying a few chips to play with, so hopefully I'll get some LEDs lit and switches read.

David
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Sun Aug 21, 2022 9:19 am     Reply with quote

I have to ask why on earth you are looking at using such an old part?.
It is flagged as 'obsolete' on the manufacturers website.
Use the Microchip MCP23017 (or the S17 for an SPI interface device).
Drivers for this are with the compiler.
djsb



Joined: 29 Jan 2011
Posts: 34

View user's profile Send private message

PostPosted: Sun Aug 21, 2022 10:07 am     Reply with quote

I'm trying to reverse engineer and understand a system that has a mask programmed microcontroller. Yes, it would be a fairly trivial exercise to use a modern I2C based port expander, but how that would be able to co-exist with the existing Philips MAB8440P microcontroller I'm not sure. This is just a hobby project for me, and I'm using it as a learning opportunity. I don't want to redesign the WHOLE digital subsystem just yet. The service manual for the Tuner is available here if your curious

https://elektrotanya.com/revox_b261_serv.pdf/download.html

Thanks for your help so far.


PS, I'm gradually working out the LCD mapping. Got 8 segments on digit 5 mapped today and got a ZERO lit on the LCD. It's a slow process.
PPS, The sound from this tuner is something to behold. It really sounds beautiful and is used as a reference tuner by the BBC. The stations jump about a bit randomly, though, so there's a glitch somewhere on the digital side of the system.
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Mon Aug 22, 2022 1:05 am     Reply with quote

OK.

Key thing to understand, is what this signalling standard is. It is not really
a 'bus'. They just used that as a term. It is a very simple set of definitions
of how to handle clocking data 'into' a shift register on a chip. Nothing more.

It defines how the clocking is handled, and the way this generates the 'load'
signal at the end to transfer the data from the shift register into the chip's
actual latches. This is the extra clock at the end after the shift signal
is raised.
Now all it defines is how to clock the data in. Nothing else. How many
bits the chip requires, and what the bits do, is completely down to the
chip's data sheet. It is just a 'transfer N bits of data to a chip' protocol.

Generalise the routine I posted, so you can specify 'N', then you can just call
this with the correct data layout for the chip involved.
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