Like I said, accident or desperation. I assume many saw animals in the wild eating things and decided to eat it as well. Of course then they had to determine a better way to eat it.
Take bread for example. I imaging they tried eating the wheat but it was difficult so they decided to grind it up with a rock to make it a little easier to chew. Then when it was too dry they decided to add some water to it. At some point they figured why not heat it up some and viola, flatbread.
Desperation is always my first assumption. It makes sense to try it after seeing other animals eat things first too.