The rule is the same whether you are contacted by the prosecutor, the defense attorney, or an investigator acting on behalf of either side:
You can talk to them if you choose to, but you are not obligated to speak to them if you don't want to.
If you are served with a subpoena, you are required to go to court as noted on the subpoena. A subpoena must be given to you in person; if you receive a subpoena in the mail, you are not required to go to court unless you call the lawyer who sent it and acknowledge that you received it.