Thread: Beginner!!! Please help

  1. #46
    Registered User
    Join Date
    Nov 2008
    Location
    Leicester, UK
    Posts
    35
    Quote Originally Posted by matsp View Post
    That's probably because 0x02 and 0x08 are "invisible" in hyperterminal.
    --
    Mats
    So, does that mean that numbers are always "invisible" to the hyperterminal by default?

  2. #47
    Technical Lead QuantumPete's Avatar
    Join Date
    Aug 2007
    Location
    London, UK
    Posts
    894
    Quote Originally Posted by reemaambekar View Post
    So, does that mean that numbers are always "invisible" to the hyperterminal by default?
    Not at all, but you're sending ASCII code 2 and 8, which are (End of Text) and (Backspace) respectively. For two and eight you need to send ASCII codes 50 and 56 or 0x32 and 0x38 in hex.

    QuantumPete
    "No-one else has reported this problem, you're either crazy or a liar" - Dogbert Technical Support
    "Have you tried turning it off and on again?" - The IT Crowd

  3. #48
    Registered User
    Join Date
    Nov 2008
    Location
    Leicester, UK
    Posts
    35
    Quote Originally Posted by QuantumPete View Post
    Not at all, but you're sending ASCII code 2 and 8, which are (End of Text) and (Backspace) respectively. For two and eight you need to send ASCII codes 50 and 56 or 0x32 and 0x38 in hex.

    QuantumPete
    I don't have to send ASCII 0x02 and 0x08. 0x02 and 0x08 are just the data which i need to send.

  4. #49
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by reemaambekar View Post
    I don't have to send ASCII 0x02 and 0x08. 0x02 and 0x08 are just the data which i need to send.
    Yes, and unless you have a better way to "see" what you are doing, such characters will be INVISIBLE - even of 0x02 is visible (it possibly is - on a PC it's a smiley face, I think), 0x08 will be a backspace and go back so that the NEXT character written writes over the 0x02.

    At this point, you may want to find a program that can log from a serial port to a file or some such, so that you can see what is ACTUALLY going on. I've written applications to do this more than once - including one that logged the traffic between a ISDN modem and it's controlling computer in both directions at once when browsing a web-site. Unfortunately, it was written for OSE, which is an embedded OS, so it's probably not much use to anyone here (should I find the source code somewhere).

    --
    Mats
    Last edited by matsp; 12-03-2008 at 09:46 AM.
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #50
    Registered User
    Join Date
    Nov 2008
    Location
    Leicester, UK
    Posts
    35
    Quote Originally Posted by matsp View Post
    Yes, and unless you have a better way to "see" what you are doing, such characters will be INVISIBLE - even of 0x02 is visible (it possibly is - on a PC it's a smiley face, I think), 0x08 will be a backspace and go back so that the NEXT character written writes over the 0x02.

    At this point, you may want to find a program that can log from a serial port to a file or some such, so that you can see what is ACTUALLY going on. I've written applications to do this more than once - including one that logged the traffic between a ISDN modem and it's controlling computer in both directions at once when browsing a web-site. Unfortunately, it was written for OSE, which is an embedded OS, so it's probably not much use to anyone here (should I find the source code somewhere).

    --
    Mats
    Hello again !!!

    Just to check that my function is running fine, I am now using the hyperterminal and ASC0 port.

    My code is as follows:
    Code:
    void ASC0_send()
    {
    	int i,data = 0;
    	unsigned char sd[] = {'W','N,'P'};
    		for(i=0;i<3;i++)
    	{
    		data = sd[i];
    		ASC0_vSendData (data);
    	}
    }
    When I run the code, it only displays 'WP' and doesn't consider 'N'.

    Am I missing something here?

  6. #51
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Is your ASC0_vSendData() not waiting if the port is busy, perhaps? Otherwise I don't know.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  7. #52
    Registered User
    Join Date
    Nov 2008
    Location
    Leicester, UK
    Posts
    35
    Quote Originally Posted by matsp View Post
    Is your ASC0_vSendData() not waiting if the port is busy, perhaps? Otherwise I don't know.

    --
    Mats
    Code:
    //****************************************************************************
    // @Function      void ASC0_vSendData(uword uwData) 
    //
    //----------------------------------------------------------------------------
    // @Description   This function writes a send data initialization word into 
    //                the transmit buffer register.
    //                
    //                Note: 
    //                In a multiprocessor system the master with this function 
    //                has the possibility to send data to the selected slave. To 
    //                achieve this, the 9th bit must set on zero.
    //
    //----------------------------------------------------------------------------
    // @Returnvalue   None
    //
    //----------------------------------------------------------------------------
    // @Parameters    uwData: 
    //                Data to be send
    //
    //----------------------------------------------------------------------------
    // @Date          26/11/2008
    //
    //****************************************************************************
    
    // USER CODE BEGIN (SendData,1)
    void ASC0_send()
    {
    	int i,data = 0;
    	unsigned char sd[] = {'W','O','P'};
    		for(i=0;i<3;i++)
    	{
    		data = sd[i];
    		ASC0_vSendData (data);
    	}
    }	
    
    // USER CODE END
    
    void ASC0_vSendData(uword uwData)
    {
      ASC0_TBIC_IR = 1;        //  reset transmit buffer interrupt request 
      ASC0_TBUF    = uwData;   //  load transmit buffer register
    
    } //  End of function ASC0_vSendData
    This is the actual full ASC0_VsendData function. Does it make more sense now?

  8. #53
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Looks like you need some sort of "wait for completion" before you send the next data item. Since I have no idea what OS you are using, etc, I can't really comment on how you should go about doing that.

    Code:
      ASC0_TBIC_IR = 1;        //  reset transmit buffer interrupt request
    I expect this would mean that you get an interrupt at some point later, when the transmit is "ready" to send the next char.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  9. #54
    Registered User
    Join Date
    Nov 2008
    Location
    Leicester, UK
    Posts
    35
    Quote Originally Posted by matsp View Post
    Looks like you need some sort of "wait for completion" before you send the next data item. Since I have no idea what OS you are using, etc, I can't really comment on how you should go about doing that.

    Code:
      ASC0_TBIC_IR = 1;        //  reset transmit buffer interrupt request
    I expect this would mean that you get an interrupt at some point later, when the transmit is "ready" to send the next char.

    --
    Mats
    I managed to display 'WNP' entirely on the hyperterminal. The problem was with the predefined ASC0_vSendData function. New function is as follows:
    Code:
    void ASC0_vSendData(uword uwData)
    {
      ASC0_TBIC_IR = 0;        //  reset transmit buffer interrupt request reset=0; set=1
      ASC0_TBUF    = uwData;   //  load transmit buffer register
    	while (ASC0_TBIC_IR == 0); //wait till transmission finish
    } //  End of function ASC0_vSendData
    This code prints 'WNP' properly now.

    Thanks for your help.

  10. #55
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    That is a possible solution, but I would ask someone who knows more about the OS/runtime environment, because there may be a better way to "wait for an interrupt" than to poll the bit for the interrupt control.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  11. #56
    Registered User
    Join Date
    Nov 2008
    Location
    Leicester, UK
    Posts
    35
    Quote Originally Posted by matsp View Post
    That is a possible solution, but I would ask someone who knows more about the OS/runtime environment, because there may be a better way to "wait for an interrupt" than to poll the bit for the interrupt control.

    --
    Mats
    But, will the way I am doing it, affect my code/hardware in any way?

  12. #57
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by reemaambekar View Post
    But, will the way I am doing it, affect my code/hardware in any way?
    If you have a RTOS that supports multiple tasks/processes/threads, then you waiting like that will eat time off other tasks(etc) that may want to run. If the processor has power-management it may want to "go to sleep" if there's no activity going on, so again, your solution will affect the power-consumption in that case.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  13. #58
    Registered User slingerland3g's Avatar
    Join Date
    Jan 2008
    Location
    Seattle
    Posts
    603
    I would agree, that waiting till the transmit queue is ready to accept more data is a bit overkill. Halting the OS a bit to wait is much more efficient, but a bit slower. Coming up with an optimum wait in ms's will require some testing.

  14. #59
    Registered User Sshakey6791's Avatar
    Join Date
    Nov 2008
    Location
    -
    Posts
    57
    This might be a stupid remark but why would you want to learn c programming when you can learn C++..... Isn't C++ better then C ? I'm really not sure so don't attack me

  15. #60
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by Sshakey6791 View Post
    This might be a stupid remark but why would you want to learn c programming when you can learn C++..... Isn't C++ better then C ? I'm really not sure so don't attack me
    Well, in this case, the target system is a single-board micro-computer, so it is not necessarily a good target for the heavy tools of C++. And the code being discussed here would be marginally different either way - or do you know something that I do not know in the particular project?

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Same old beginner question...
    By Sharmz in forum C Programming
    Replies: 15
    Last Post: 08-04-2008, 11:48 AM
  2. What are some good beginner programs I shouold make?
    By oobootsy1 in forum C# Programming
    Replies: 6
    Last Post: 08-09-2005, 02:02 PM
  3. Books, Beginner, MustHave
    By Zeusbwr in forum C++ Programming
    Replies: 9
    Last Post: 10-25-2004, 05:14 PM
  4. Windows programming for beginner (Absolute beginner)
    By WDT in forum Windows Programming
    Replies: 4
    Last Post: 01-06-2004, 11:21 AM