confusion about IO PORT on HC908

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

confusion about IO PORT on HC908

4,560 Views
ryan_
Contributor I
HI,
 
I am quite confused about the HI-Z status of IO port on HC908 MCU.
 
When I want to connect some 1-wire parts to HC908 I need to set the 1-wire pin high or low.
 
I used to connect a pull up resistor on the 1-wire pin to VCC and control the pin through the DDRx register instead of PTx register, for instance, I will first set this 1-wire pin port register to 0 thus to keep this pin latch to 0 and this will remains unchangeable, when I need the 1-wire pin to be low, write DDRx=1, if I need it to be high,write DDRX=0 the external pull up resistor will pull up the bus to high level. This works on avr MCUs.
 
When I use this on HC908, I failed. Changing the DDRx doesn't change the pin voltage level. I don't know whether I am somewhere wrong or the HC908 MCUs just work so.
 
Anyone knows this, I would like to hear you very much.
 
Regards,
ryan


Message Edited by ryan. on 2007-11-26 08:57 AM
Labels (1)
0 Kudos
Reply
8 Replies

2,408 Views
Ake
Contributor III
Hi again,
I spent some more time on your problem and discovered the following:
 
1) The port PTB4 - PTB7 can all behave in the similar way. I have not tested PTB0 - PTB3 as they are part of the ICS board.
 
2) The disappearing output pin, depends on if there is a pullup resistor present when the MCU is reset or when the port ctl byte is written (I have not found that out yet).
 
3) Once the DDRB registers have been programmed, the pullup resistors can be connected and everything behaves as normal.
 
4) It is not possible to get rid of it by changing the program. (That's what it seems to me)
 
I will tell you more as soon as I have heard something.
 
Regards,
Ake
0 Kudos
Reply

2,408 Views
Ake
Contributor III
Hi,
Well finally I think I know what is happening.
I wrote a small piece of code to test the mysterious PTB4.
 

#define WONTWORK TRUE
void main(void) {
        CONFIG1_COPD = 0;
        PTB_PTB4 = 0;
#if WONTWORK       
        DDRB_DDRB4 = 0; //set up DDRB4 as an inport- does not work
#else
        DDRB_DDRB4 = 1; //set it up as an outport - works
#end
       
        PTB_PTB5 = 0;
       
  for(;:smileywink: {
        DDRB_DDRB4 = 0;   //it does not work on PTB4
        DDRB_DDRB4 = 1;
        DDRB_DDRB5 = 0;   //it works on PTB5
        DDRB_DDRB5 = 1;
  } /* loop forever */
}
It looks like that if you want PTB4 to be an outport, you mustn't set it up as an inport to begin with.
If you do, it is impossible to switch to an outport.
The odd thing is that PTB5 behaves as the data book says.
I will discuss it further, maybe it is something on the ICS08JL board that makes it behave so strange.
 
Thanks for your initial message!
 
Regards
Ake
0 Kudos
Reply

2,408 Views
ryan_
Contributor I
Hi,bigmac
 
I use an IO pin share with a ADC function pin.
 
How can I know which pin on HC908 can be used as my way (HI-Z)?
 
I mean, there are many ports on the device share different functions, e.g ADC KBI IRQ TIM SPI SCI... all of them share with GPIOs, maybe you can give me some suggestion like "you can't use IRQ,ADC pin" or "you can use SPI and ADC bi-function pin to do that".
 
Regards
ryan
0 Kudos
Reply

2,408 Views
bigmac
Specialist III
Hello Ryan,
 
You may use any pin for your purpose, provided it supports both input and output (as most do).  If it has alternate functions, you should be fine provided you do not enable any of the alternate functions (for that pin only).
 
For example, you wouldn't be able to use TIM output compare to directly generate your output to the pin.  (The TIM channel, if used, would need to operate as "interrupt only".)
 
Using PTB4 should work in the manner you require, provided you do not select the ADC4 channel for an ADC measurement.  You may use any of the other ADC channels for analog measurement.
 
It is not clear which state you cannot correctly achieve.
 
Regards,
Mac
 


Message Edited by bigmac on 2007-11-26 11:16 PM
0 Kudos
Reply

2,408 Views
bigmac
Specialist III
Hello Ryan,
 
Check that you haven't also enabled one of the alternative functions associated with the pin.  When an alternative function is enabled, this will usually take precedence over the GPIO operation.
 
Also bear in mind that the pin that supports the IRQ function is input only for many HC908 derivatives.
 
Regards,
Mac
 


Message Edited by bigmac on 2007-11-26 10:38 PM
0 Kudos
Reply

2,408 Views
Ake
Contributor III
Ryan,
I cannot see anything wrong with your code.
Have you checked that the I/O that you have selected can be programmed as an output?
What kind of HC908 are you using?
Can you provide the source code of your program?
 
Regards,
Ake
0 Kudos
Reply

2,408 Views
ryan_
Contributor I
Hi, Ake
 
My target device is mc908jl16 and I use PTB_PTB4 as the 1-wire bus pin.
 
I have finish the project by not using DDRB as a control.
Instead I use the PTB&DDRB together to control the pin voltage level and it works fine.
 
I just want to know: Are HC908 MCUs enable to do such work by using just keep PORTx=0 and adjust DDRx to control the high/low voltage level on a IO pin?
 
Regards
ryan
 
0 Kudos
Reply

2,408 Views
Ake
Contributor III
Ryan,
I picked up a HC908JL16 and put it into a ICS08JL board.
I connected an external pullup resistor to pin PTB4 and connected an oscilloscope.
I then wrote a small program and ran it.
The scope showed a strait line.
I scratched my head.
I then added a wiggling on PTB5.
There it jumped up and down.
 
I looked at the PC again. If you look at DDRB_DDRB4, it is always set, so it will never be an output port.
 
I will talk to my collegues and get back to you about your finding.
 
Regards,
Ake
0 Kudos
Reply